Filemanager download via HTTP GET

I’m trying to enable simple file download from the Filemanager on double click.

The existing examples show a call through a PHP script but, I want to delivery directly from the CDN using HTTP GET.

By attaching to onItemDblClick from a TreeView, we can do the necessary work from a standalone TreeView example but, how do I enable the same simple HTTP GET based functionality for the Filemanager widget proper?

While I’m asking about download, what about upload?

Must the Webix client call a backend PHP script? Or can it issue an HTTP POST directly to a named folder?

If so, can the response message be synthesized from within the application using an override? Or must the service(CDN) return the expected JSON formatted response?

In this case, requiring the backend to conform to the webix client is not a desirable option.

Ok, I decided to override the filemanager download method using something like:

    $$("files").download = function (id) {
      var resource = $$("files").getItem (id);
      if (resource && resource.type == "file")
      {
         // Custom code here
          window.open(localURL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
      }
    };

Although, it would be nice to have a proxy that supports customization, this gets me far enough to download a file on double click.

Still working on upload and delete…

Ok, after a little more research I’ve learned 2 things.

First, I can override filemanager.delete, as I did with the download function, and get everything I need.

Second, for most browsers, uploading files requires the use of the FormData interface and that will break my plan to post files directly to the CDN storage interface; an application server is required to parse and remove the “WebKitFormBoundary” headers surrounding the data of interest.

Happy to hear from anyone else who managed to work around this, but it looks like I’ve reached the end of this journey.

Hello,

What concerns file downloading, there’s no possibility to customize it via proxy, unfortunately.

So, you can either modify the download method of a File Manager widget and force the webix.send to issue a GET request

webix.protoUI({
   name:"myFileManager"
   download:function(id){
	var url = this.config.handlers.download;
	if (url)
                //adding the third parameter with method name
		webix.send(url, { action:"download", source: id }, "GET");
   }
}, webix.ui.filemanager);

webix.ui({ view:"myfilemanager", ...})

Or, catch the onBeforeRun event and call your download logic there

$$("files").attachEvent("onBeforeRun",function(id){
    //your logic
    //returning false is vital since it cancels the default processing.  
    return false;
})

From my side, theonBeforeRun event is more flexible. It does not affect other File Manager instances while propotype modifications do.

As to the uploading, the File Manager will issue a POST request with the necessary formData in its body. The required response looks like this:

{
    "folder":"\\/",
    "value":"test.xlsx",
    "id":"test.xlsx",
    "type":"xlsx",
    "status":"server"
}

And, at last, to redefine deletion you can provide a custom proxy: http://webix.com/snippet/704b080c

Outstanding,

Helga this is really helpful information! I’ll go back and apply the changes you recommend and let you know what comes of the change.

Yours,
McNoober