3

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.

Mohammed H
  • 6,880
  • 16
  • 81
  • 127
InsaurraldeAP
  • 682
  • 7
  • 16
  • 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 Jul 01 '12 at 07:53
  • There is no need for a new tag here, we already have *two* to cover Google Drive. – Charles Jul 01 '12 at 08:30

1 Answers1

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.

Lawliet
  • 90
  • 8
Sandro
  • 566
  • 1
  • 3
  • 8