Results 1 to 10 of 16

Thread: Question - download file to predefined location

Threaded View

Previous Post Previous Post   Next Post Next Post
    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    May 2010
    Vote Rating

    Default Answered: Question - download file to predefined location


    I have a question about Sencha Desktop Packager regarding downloading of files.

    I want to build an application where the user can select an online file, edit it on the local computer, and submit/upload it when the file is changed. In the support pages I can find how to open a file, and monitor the file/folder when it changes. Uploading can be done using regular HTML.

    But I can't find the option to download the selected file to a (temporary) location. When I just link to the file, I don't know what the location will be, so that's not an option.

    Is it possible to let my app download a file to a location on the user's computer without the user having to choose the location?

    Thanks in advance.

    Greetings, vosManz

  2. Great question. Currently the way to save a file to disk from a remote URL would be to use XHR, download the binary data, and then save that binary data by passing it in a format compatible with, like so:

    function saveFileToDisk(url, dest, callback) {
        var xhr = new XMLHttpRequest();
        xhr.onload = function() {
            var typedData = new Uint8Array(xhr.response),
                ln = typedData.length,
                data = new Array(ln),
            for (var i = 0; i < ln; i++) {
                data[i] = typedData[i];
            result =, data);
        xhr.onerror = function() {
   'GET', url);
        xhr.responseType = 'arraybuffer';
    Note that this requires the "allowCrossSite" security manifest setting to be enabled to bypass x-domain security policies. Also, if you are dealing with text files, you can instead just save the xhr.responseText and pass that directly to as a string, instead of saving it as binary data:

    result =, xhr.responseText);
    This generally is a pain point right now with very large binary files. For files that are < 15-20mb it is generally acceptable. We are working to enhance our file I/O APIs to add in asynchronous streaming and compatibility with the Typed Arrays specification.

    You can listen to click events on those particular file hyperlinks, and handle that click event by saving the file to disk. You could attach a click handler directly on the hyperlinks...

    <a href="http://some/url/to/my/file.txt" onclick="saveFileToDisk(this.href, + 'file.txt', function(){}); return false;">Click Here!</a>
    ...or use the cleaner way and catch all clicks on hyperlinks...

    document.body.addEventListener('click', function(e) {
        var t =;
        if (t.tagName == 'A' && t.dataset.fileName) {
            saveFileToDisk(t.href, + t.dataset.fileName, function(success) {
                if (success) // do something
                else // do something
    }, true);
    <a href="http://some/url/to/my/file.txt" data-fileName="file.txt">Click Here!</a>
    <a href="http://some/url/to/my/file2.txt" data-fileName="file2.txt">Click Here!</a>
    Hope that helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts