Google Drive API JavaScript - Insert file - Stack Overflow

I'm trying to "insert" a Drive file.I've made the auth and it works right :)But wh

I'm trying to "insert" a Drive file. I've made the auth and it works right :)

But when I try to create (insert) a new file from JS, it creates one, but a file named "Untitled" with no extension at all. (I have a sync folder on my file system, and it is the same thing).

My code is this:

 function createNewFile(  ) {
    gapi.client.load('drive', 'v2', function() {
    var request = gapi.client.drive.files.insert ( {
        "title" : "cat.jpg",
        "mimeType" : "image/jpeg",
        "description" : "Some"
        } );
    request.execute(function(resp) { console.log(resp); });
    });
 }

Any idea about what is wrong? I can list files from my drive from JS, and this code creates this "untitled" and no extensioned file.

I'm trying to "insert" a Drive file. I've made the auth and it works right :)

But when I try to create (insert) a new file from JS, it creates one, but a file named "Untitled" with no extension at all. (I have a sync folder on my file system, and it is the same thing).

My code is this:

 function createNewFile(  ) {
    gapi.client.load('drive', 'v2', function() {
    var request = gapi.client.drive.files.insert ( {
        "title" : "cat.jpg",
        "mimeType" : "image/jpeg",
        "description" : "Some"
        } );
    request.execute(function(resp) { console.log(resp); });
    });
 }

Any idea about what is wrong? I can list files from my drive from JS, and this code creates this "untitled" and no extensioned file.

Share Improve this question edited Nov 16, 2012 at 7:20 Mohammed H 7,05819 gold badges82 silver badges128 bronze badges asked Jul 1, 2012 at 7:52 InsaurraldeAPInsaurraldeAP 6827 silver badges16 bronze badges 2
  • i dont have 1500 points, so i cannot create a new tag on stackOverflow, it is "google-drive-api" instead of google-drive-sdk, but it doesn't exist yet – InsaurraldeAP Commented Jul 1, 2012 at 7:53
  • There is no need for a new tag here, we already have two to cover Google Drive. – Charles Commented Jul 1, 2012 at 8:30
Add a ment  | 

1 Answer 1

Reset to default 5

I have that working like this:

function createNewFile(  ) {

    gapi.client.load('drive', 'v2', function() {

       var request = gapi.client.request({
        'path': '/drive/v2/files',
        'method': 'POST',
        'body':{
            "title" : "cat.jpg",
            "mimeType" : "image/jpeg",
            "description" : "Some"
         }
     });

      request.execute(function(resp) { console.log(resp); });
   });
}

Bear in mind that if a file with title cat.jpg already exists, this request will create another file with the same title, since files in Google Drive have unique file IDs by which are referred internally.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744989126a4604792.html

相关推荐

  • Google Drive API JavaScript - Insert file - Stack Overflow

    I'm trying to "insert" a Drive file.I've made the auth and it works right :)But wh

    19小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信