【问题标题】:Google Drive API returns Folder ID 404 but the folder ID is correctGoogle Drive API 返回文件夹 ID 404 但文件夹 ID 正确
【发布时间】:2021-08-05 06:23:59
【问题描述】:

所以我正在尝试将一些文件上传到特定文件夹,我有它,它在查询时可以完美运行。但是,当我尝试上传到该文件夹​​时,出现 404 错误。

var file = document.getElementById('input-file').files[0];
var metadata = {
      'mimeType': file.type,
    'name': name, // Filename at Google Drive
    'parents': ['0AN75N3P23eTJUk9PVA'], // Folder ID at Google Drive
};

var accessToken = gapi.auth.getToken().access_token; // Here gapi is used for retrieving the access token.
var form = new FormData();
form.append('metadata', new Blob([JSON.stringify(metadata)], { type: 'application/json' }));
form.append('file', file);

var xhr = new XMLHttpRequest();
xhr.open('post', 'https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart');
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.responseType = 'json';
xhr.onload = () => {
    console.log(xhr.response.id); // Retrieve uploaded file ID.
};
xhr.send(form);

【问题讨论】:

  • 也许问题出在'name': name ...它是否定义在全局范围之外的某个地方?
  • @JaromandaX 不!我检查了值,但谢谢!

标签: javascript api python-requests google-drive-api


【解决方案1】:

我必须在表单中添加“supportsAllDrives: true”,因为该文件夹是How to upload file to Group Drive (Shared Drive) with Google Drive API V3? 的共享驱动器

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多