1

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".

0

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Yup, It works! This is what I want. (There is a small syntax error; You forgot to add curly bracket around "'resource': data". Please update the answer.)
Wow! I got the answer from Google Team!
Thank, I updated my answer. My team and I monitor the google-drive-sdk tag and are very happy to help! :)
2

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.

1 Comment

just would like to update with 'path': '/upload/drive/v2/files'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.