12

我尝试如下。但该文件将进入根目录(我的驱动器)。

var metadata = {
  'title': fileData.fileName,
  'mimeType': contentType,
  'parents':["0B6NmmF3ovpsbExuOEc1R2JzSFEp"] // It is one of my folder's id.
};

var base64Data = btoa(reader.result);
var multipartRequestBody =
    delimiter +
    'Content-Type: application/json\r\n\r\n' +
    JSON.stringify(metadata) +
    delimiter +
    'Content-Type: ' + contentType + '\r\n' +
    'Content-Transfer-Encoding: base64\r\n' +
    '\r\n' +
    base64Data +
    close_delim;

var request = gapi.client.request({
    'path': '/upload/drive/v2/files',
    'method': 'POST',
    'params': {'uploadType': 'multipart'},
    'headers': {
      'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
    },
    'body': multipartRequestBody});

 request.execute(callback);
4

1 回答 1

27

我解决了这个问题。

错误在这一行:

'parents':["0B6NmmF3ovpsbExuOEc1R2JzSFEp"]

该行应该是:

'parents':[{"id":"0B6NmmF3ovpsbExuOEc1R2JzSFEp"}]

文档可以在https://developers.google.com/drive/web/folder找到

于 2012-10-15T05:31:52.377 回答