I wrote a javascript method to create folder in google drive.
function createFolder(){
data = new Object();
data.title = 'New Folder';
data.parents = [{"id":jQuery('#parent').val()}];
data.mimeType = "application/vnd.google-apps.folder";
gapi.client.drive.files.insert(data).execute(function(fileList){});
}
It creates a file named 'Untitled' with mimeType "application/octet-stream" and parent root directory. This code supposed to create a folder named "New Folder".
Your code is almost correct, you are just not sending the request body correctly. This snippet should work:
function createFolder(){
data = new Object();
data.title = 'New Folder';
data.parents = [{"id":jQuery('#parent').val()}];
data.mimeType = "application/vnd.google-apps.folder";
gapi.client.drive.files.insert({'resource': data}).execute(function(fileList){});
}
The body of the request is specified as the resource
element.
I solved the issue as given below.
function createFolder() {
data = new Object();
data.title = 'New Folder';
data.parents = [{"id":jQuery('#parent').val()}];
data.mimeType = "application/vnd.google-apps.folder";
var request = gapi.client.request({
'path': '/drive/v2/files',
'method': 'POST',
'body': JSON.stringify(data)});
request.execute(function(){});
}
But I want to know how to do it using gapi.client.drive.files.insert .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.