I've been trying to upload a file using the Google Drive API but I'm facing an issue and I can't seem to find the answer. This happens when uploading an image, with text files, it seems to be ok.
Following the documentation here: https://developers.google.com/drive/api/v3/manage-uploads I need to form the request like this
I've tried either from POSTMAN or from Salesforce Apex and got the same issue.
I'm sending the image encoded as Base64, but the images are not getting decoded on the Google Drive side, so the issue is that there is no preview and can't open the file. If I download the file and open it on a text editor, the content is just text.
This is the image opened from VS Code
I think that you are trying to upload the base64 data. So how about this modification?
POST https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart HTTP/1.1
Authorization: Bearer [YOUR_AUTH_TOKEN]
Content-Type: multipart/related; boundary=foo_bar_baz
Content-Length: [NUMBER_OF_BYTES_IN_ENTIRE_REQUEST_BODY]
--foo_bar_baz
Content-Type: application/json; charset=UTF-8
{
"name": "myObject"
}
--foo_bar_baz
Content-Type: image/jpeg
Content-Transfer-Encoding: base64 <--- Added this.
[JPEG_DATA]
--foo_bar_baz--
Content-Transfer-Encoding: base64
to the data part.If this didn't resolve your issue, I apologize.