1

I have web application that can download from dropbox.com. The application is written using Javascript. I'm using the dropbox.min.js http://code.google.com/p/dropbox-js/ library running on a client. This is a function of the library:

client.readFile(name, function(error, data) {
   if (error) {
      return showError(error);  // Something went wrong.
   }
   saveFile(name, data);
});

saveFile(name, data) is my function doing the following:

var saveFile = function(file, data)
{
    var xmlhttp = getXmlHttp(); 
    xmlhttp.open('POST', 'saving.php', true); 
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    xmlhttp.send("fileName=" + file + "&data=" + data); 

}

function getXmlHttp(){
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

The problem is: while I'm trying to download assets (e.g. jpg doc, gif, etc.), I only receive 1kb instead of the full file. Are there any workarounds?

4

1 に答える 1

0

公式のJavaScript ライブラリは、XHR レベル 2 (Chrome、Firefox、IE 10) をサポートするブラウザーでバイナリ ファイルをダウンロードできます。

入門ドキュメントのサンプル コードを参照し、blob: trueを呼び出すときにオプションを使用しますreadFile

于 2012-11-26T04:31:38.817 に答える