上传公共文件gdrive api并获取公共链接

时间:2014-02-08 23:27:35

标签: javascript google-drive-api

您好我正在使用javascript中的GDrive api开发一个Web应用程序。

在我的页面中,我可以将文件上传到记录人员的GDrive文件夹中。

我想要的是该文件是对其他用户的公共访问,并带有下载文件的链接。

 var reader = new FileReader();
 reader.readAsBinaryString(fileData);
 reader.onload = function(e) {
      var contentType = fileData.type || 'application/octet-stream';
      var metadata = {
        'title': fileData.name,
        'mimeType': contentType
      };
      var body = {
        'value': 'google account',
        'type': 'anyone',
        'role': 'reader'
      };
      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});
      if (!callback) {
        callback = function(file) {
          console.log(file)
        };
      }
      request.execute(callback);
    };

0 个答案:

没有答案
相关问题