Google Drive API converting binary files to UTF-8?

283 Views Asked by At

I am using google drive v3 api in javascript to upload some files. Since the API is not able to directly upload, I need to create the file, then PATCH it's content. I am doing so in this way:

var pdf_file_content = some_binary_data;

gapi.client.drive.files.create({
  uploadType: 'media',
  name: 'my_nice_file.pdf',
  parents: [export_dir],
  body: {
    mimeType: 'application/pdf',
  }
}).then(
  function(res_creation) {
    gapi.client.request({
      path: '/upload/drive/v3/files/' + res_creation.result.id,
      method: 'PATCH',
      headers: {'Content-Type': 'application/pdf',},
      params: {
        uploadType: 'media'
      },
      body: some_binary_data
    });
  });
})

However, the content the I download differs from the some_binary_data, as it is being converted to UTF-8 somewhere by the API itself (I checked printing the length of my binary data and finally the length of the downloaded file result). Example is from original byte 81, I get after patching a C2 81.

The documentation is terrible.

Any ideas on what may be going on ?

Thank you !

0

There are 0 best solutions below