Jquery 谷歌硬盘下载相同内容的文件

Jquery 谷歌硬盘下载相同内容的文件,jquery,google-api,google-drive-api,google-picker,google-api-js-client,Jquery,Google Api,Google Drive Api,Google Picker,Google Api Js Client,我正试图从我的谷歌硬盘中选择两个图像,并尝试下载base64中的内容,如图所示,并将其发送到服务器端,以便将文件下载到我的服务器文件夹中,但下载后,我能够获得两个文件,但内容相同。我不知道我哪里做错了谁能帮我解决这个问题 对于单个图像,它工作正常。问题是当我选择多个文件时。 有时选择2个文件,其中一个文件被下载,而另一个文件未被下载,有时出现403错误。google for api v3上的文档没有问题 "error": { "errors":

我正试图从我的谷歌硬盘中选择两个图像,并尝试下载base64中的内容,如图所示,并将其发送到服务器端,以便将文件下载到我的服务器文件夹中,但下载后,我能够获得两个文件,但内容相同。我不知道我哪里做错了谁能帮我解决这个问题

对于单个图像,它工作正常。问题是当我选择多个文件时。 有时选择2个文件,其中一个文件被下载,而另一个文件未被下载,有时出现403错误。google for api v3上的文档没有问题

 "error": {
    "errors": [
        {
            "domain": "usageLimits",
            "reason": "dailyLimitExceeded",
            "message": "Daily Limit Exceeded"
        }
    ],
        "code": 403,
            "message": "Daily Limit Exceeded"
}
获取数据的代码:

 function pickerCallback(data) {
    var fileId;
    var gdriveids = [];
    var gdrivebas64 = [];
    var selectedfilenames=[];

    if (data.action == google.picker.Action.PICKED) {
        for (var i = 0; i < data.docs.length; i++) {
            fileId = data.docs[i].id;
            gapi.load('client', function () {
                gapi.client.load('drive', 'v3', function () {
                    var file = gapi.client.drive.files.get({ 'fileId': fileId, fields: '*' });
                    file.execute(function (resp) {
                        console.log(resp);
                        var maxFileSize = 20971520/*20MB(20*1024*1024)*/;
                        filesize = resp.size;
                        displayfilesize = formatBytes(filesize);
                        filesizes.push(displayfilesize);
                        morefiles = maxfiles - imgcount;
                        if (gdriveids.length > morefiles) {
                            $('#filelist').html("You can add only " + morefiles + " more file(s).");
                            $('#myProgress').show();
                        } else {
                            if (filesize < maxFileSize) {
                                $('#myProgress').show();
                                $('.images').html("");

                                console.log("FolderName : " + inputFolderName);
                                console.log("Files : " + selectedfilenames);

                                var accessToken = oauthToken;
                                var xhr = new XMLHttpRequest();
                                xhr.open("GET", "https://www.googleapis.com/drive/v3/files/" + fileId + '?alt=media', true);
                                xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
                                xhr.responseType = 'arraybuffer'
                                xhr.onload = function () {
                                    if (xhr.status == 200) {
                                        var base64 = base64ArrayBuffer(xhr.response);
                                        gdrivebase64.push(base64);

                                        $.ajax({
                                            type: "POST",
                                            url: "test.aspx/GetFile",
                                            data: JSON.stringify({
                                                InputFolderName: inputFolderName, FileNames: selectedfilenames, Base64: gdrivebase64
                                            }),
                                            contentType: "application/json; charset=utf-8",
                                            dataType: "json",
                                            success: function (msg) {
                                                if (msg.d == "True") {
                                                    console.log("Success");
                                                } else {
                                                    console.log("Failed");
                                                }
                                            }
                                        });
                                    } else {
                                        $('#filelist').html('Error! Please try again.');
                                    }
                                }
                                xhr.send();
                            }
                        }
                    })
                });
            });
        };
    }
}

不确定是否所有的问题都能由此解决,但您正在使用来自所有以前迭代的文件gdrivebase64(在每个后续迭代中选择的文件名)的数据发出ajax请求。这样,第一个文件的数据将发送两次。我认为您实际上希望在for循环之后和之外发出此请求,或者在发出ajax请求时只提供当前文件的数据,而不是一个包含所有这些数据的数组gdrivebase64,selectedfilename。您能检查一下吗?不确定您的所有问题是否都能通过此解决,但您正在使用来自所有以前迭代的文件gdrivebase64的数据发出ajax请求,在每个后续迭代中选择文件名。这样,第一个文件的数据将发送两次。我认为您实际上希望在for循环之后和之外发出此请求,或者在发出ajax请求时只提供当前文件的数据,而不是一个包含所有这些数据的数组gdrivebase64,selectedfilename。你能检查一下吗?