Skip to content Skip to sidebar Skip to footer

Dropbox Chooser Returns Corrupted File

posting here because I've not received a response over at the dropbox forums. dropbox forum post A few months ago I implemented the dropbox chooser and got everything working fine.

Solution 1:

I think the issue is that you're reading from the XMLHttpRequest's responseText field instead of response. My guess would be that this results in (incorrectly) trying to interpret the data as text characters.

EDIT: You also need to change arrayBuffer to arraybuffer to actually get an ArrayBuffer back. Then you need to check the byteLength field to get the actual number of bytes contained in the ArrayBuffer.

Note that to use the arraybuffer response type, you'll need to switch to using an asynchronous XMLHttpRequest. (Drop the false last parameter to xhr.open or change its value to true.)

EDIT2:

A working (for me) example is at https://downloadtest.site44.com. The code is as follows:

Dropbox.choose({
    success: function (files) {
        var xhr = newXMLHttpRequest();
        xhr.open('GET', files[0].link);
        xhr.responseType = 'arraybuffer';
        xhr.onreadystatechange = function (oEvent) {
            if (xhr.readyState === 4 && xhr.status === 200) {
                var buffer = xhr.response;
                console.log('File size: ' + files[0].bytes + 
                    ' | Buffer size: ' + buffer.byteLength + 
                    ' | Header size: ' + xhr.getResponseHeader('Content-Length'));
            }
        };
        xhr.send();
    },

    linkType: 'direct'
});

Post a Comment for "Dropbox Chooser Returns Corrupted File"