在HTTP请求中包含Alt =媒体参数的语法是什么。
我对此非常新鲜,因此通过反复试验学习。
我有一个JavaScript,到目前为止,它正在授权访问用户Google Drive。它创建了一些文件的数组,我可以访问meta数据以获取每个文件的下载。
function downloadFile() {
gapi.client.load('drive', 'v2', makeRequest);
}
function makeRequest() {
var request = gapi.client.request({
'path': '/drive/v2/files',
'method': 'GET',
'params': {'q': 'title contains "This"'} // retrieve all files with a filename that begins with the word "This"
});
request.execute(function(resp) {
for (i = 0; i < resp.items.length; i++) {
var dlUrl = resp.items[i].downloadUrl; //this is the url extracted from the request
var finalDlUrl = dlUrl.split("&gd=true");//the url needs to be trimmed so the last 8 characters are ignored in order to work
window.location.assign(finalDlUrl);
}
});
如何使脚本循环遍历每个文件数组元素并下载每个元素。我知道要使用" for Loop",但是触发文件下载的实际方法是什么,因此它们出现在我的浏览器下载文件夹中。
另外,它可能是相关的,使用gapi.client.request({/* etc */})
您可以创建一个iFrame,然后将SRC设置为下载值。您可能需要设置超时...
function downloadFile() {
gapi.client.load('drive', 'v2', makeRequest);
}
function makeRequest() {
var request = gapi.client.request({
'path': '/drive/v2/files',
'method': 'GET',
'params': {'q': 'title contains "This"'} // retrieve all files with a filename that begins with the word "This"
});
request.execute(function(resp) {
for (i = 0; i < resp.items.length; i++) {
var dlUrl = resp.items[i].downloadUrl; //this is the url extracted from the request
var finalDlUrl = dlUrl.split("&gd=true");//the url needs to be trimmed so the last 8 characters are ignored in order to work
downloadUrl(finalDlUrl);
}
});
}
function downloadUrl(url) {
var iframe = document.createElement("iframe");
iframe.src = url;
iframe.style.display = "none";
document.body.appendChild(iframe);
}
这是一些可能按顺序下载文件的代码:
function downloadFile() {
gapi.client.load('drive', 'v2', makeRequest);
}
function makeRequest() {
var request = gapi.client.request({
'path': '/drive/v2/files',
'method': 'GET',
'params': {'q': 'title contains "This"'}
});
request.execute(function(resp) {
downloadFiles(0, resp.items);
});
}
function downloadFiles(current, list)
{
var next = current + 1;
if(next == list.length) {
return;
}
var dlUrl = resp.items[next].downloadUrl;
var finalDlUrl = dlUrl.split("&gd=true");
var iframe = document.createElement("iframe");
iframe.src = finalDlUrl;
iframe.style.display = "none";
document.body.appendChild(iframe);
iframe.onload = function() {
downloadFiles(next, list);
};
}