0
Not a bug

Google drive API - drive.files.create method - File id not found

Soujanya Bargavi 6 jaar geleden bijgewerkt door Jarosław Błąd (CEO) 4 jaar geleden 2

I'm trying to sent a file on some Google drive folder. To succeed I translate blob in file before sending it.

So far I have seen that there is some method like Buffer, Base64, and send Blob directly to Google drive.

I have tried to send the blob directly it failed. I'm a little confusing with Buffer and Base64 so I have rather tried to use the below BlobToFile function, seems it works to process but the file is not found.

I have tried fs.something but I think I got to mastery better the Buffer and Base64 concepts.

What I'm trying to do concretely is to translate some data received from a form in a client side, compute it in Node.js side, create a file again on Node.js side and send it directly to my Google drive folder without write it on my hard disk, just upload it on the Google drive web service.

But my console returns me :

Error: File not found. code: 404, errors: [ { domain: 'global', reason: 'notFound', message: 'File not found: 1aazdz3FOCADXUuOA5E7XcOaS3297sU.', locationType: 'parameter', location: 'fileId' } ] }

Here my reactApp.js to help you figure out what it happens :

  saveAudio() {
    // convert saved chunks to blob
    const blob = new Blob(this.chunks, {type: audioType});
this.setState(blob)
     } 
  // (...) then an HTTP POST request including the blob object.

Here my quickstart.js :

module.exports.uploadFile = function(req){
 var file ;
  console.log("driveApi upload reached")
  function blobToFile(req){
    file = req.body.blob
    //A Blob() is almost a File() - it's just missing the two properties below which we will add
    file.lastModifiedDate = new Date();
    file.name = req.body.word;
    return file;
  }
console.log(typeof 42);
// upload file in specific folder
var folderId = "1aa1DD993FOCADXUDNJKLfzfXcOaS3297sU";
var fileMetadata = {
  "name": req.body.word,
  parents: [folderId]
}
var media = {
  mimeType: "audio/mp3",
  body: file
}
drive.files.create({
  auth: jwToken,
  resource: fileMetadata,
  media: media,
  fields: "id"
}, function (err, file) {
  if (err) {
    // Handle error
    console.error(err);
  } else {
    console.log("File Id: ", file.id);
  }
  console.log("driveApi upload accomplished")
});
}
-1
Under review

Hi,

Sorry, we are providing support only with problems regarding our platform. You can try asking at e.g. Stackoverflow.