Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Question - download file to predefined location

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #11
    Sencha User
    Join Date
    May 2010
    Posts
    14
    Vote Rating
    0
      0  

    Default

    Sorry for the bump again, don't want to be rude, but my evaluation copy will expire in 4 days..
    I would like to purchase a full license, but first I would like to know if I can realize what I want using Desktop Packager. Otherwise I need to find another solution.

  2. #12
    Sencha User jarrednicholls's Avatar
    Join Date
    Mar 2007
    Location
    Frederick, MD
    Posts
    1,747
    Answers
    20
    Vote Rating
    7
      1  

    Default

    Sorry for the delayed reply. Please beware that the following code snippets are written ad-hoc and not tested

    So the best thing to do would be to send the data as an ArrayBuffer/Blob, assuming it is a binary file. When you receive that changed event, you would read the file data in binary mode. Then, you would take that data and create an Uint8Array typed array, and send that via XHR:

    Code:
    var result = Ion.io.readFile(path, { mode: 'binary' });
    if (result.success) {
        var data = new Uint8Array(result.data);
        var xhr = new XMLHttpRequest();
        xhr.onload = function() {
            console.log('Success!');
        };
        xhr.onerror = function() {
            console.log('Error!');
        };
        xhr.open('POST', url, true);
        xhr.send(data);
    }
    On the backend, you would receive the data as a binary POST. For example in PHP, you read it in like this:

    Code:
    $data = file_get_contents('php://input');
    // do something with $data
    The actual way to read the binary POST data depends on your server-side stack, of course.

    If the data is just text, or can be easily base64-encoded, you can use Ion.io.readFile() in text mode (default) and still perform a standard FormData post. In short, yes it is possible to get that data up to your server automatically without the user getting involved.

    Hope that helps.

  3. #13
    Sencha User
    Join Date
    May 2010
    Posts
    14
    Vote Rating
    0
      0  

    Default

    Great! That worked perfect! Thanks for all your answers! Awesome!

    Thanks again!

  4. #14
    Sencha User jarrednicholls's Avatar
    Join Date
    Mar 2007
    Location
    Frederick, MD
    Posts
    1,747
    Answers
    20
    Vote Rating
    7
      0  

    Default

    My pleasure! Glad to hear you're up and running.

  5. #15
    Ext JS Premium Member
    Join Date
    May 2011
    Posts
    60
    Vote Rating
    1
      0  

    Default support for large file download

    Hi!

    Interesting method. Do you have any solution for large file downloads? I've to download tons of GB of files. All tries lead to an error, the remote debug port such detaches.

    Harald

  6. #16
    Ext JS Premium Member
    Join Date
    May 2011
    Posts
    60
    Vote Rating
    1
      0  

    Default

    Quote Originally Posted by jarrednicholls View Post
    ...

    Code:
    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),
                result;
    
            for (var i = 0; i < ln; i++) {
                data[i] = typedData[i];
            }
    
            result = Ion.io.writeFile(dest, data);
            callback(result.success);
        };
    
        xhr.onerror = function() {
            callback(false);
        };
    
        xhr.open('GET', url);
        xhr.responseType = 'arraybuffer';
        xhr.send(null);
    }
    ...

    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.

    Hope that helps.
    Hi, I'm facing a performance bottleneck when converting downloaded binary content to a number array just for saving, it took about 40sec to download and save a 100MB file (where the converting part took over most of the time, over 38sec). When will the mentioned enhanced I/O API be available to public release? My customer would laugh at me when they see these download rates...

Page 2 of 2 FirstFirst 12

Posting Permissions

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