当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - upload public file gdrive api and get public link

问题描述:

Hi I am developing a web application with GDrive api in javascript.

In my page I can upload a file to the GDrive folder of the logged person.

What I want is that the file is public access to other user with a link to download the file.

 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);

};

分享给朋友:
您可能感兴趣的文章:
随机阅读: