uploading file to google drive api with [RFC 2387] http request

Viewed 19

I am using retool pltaform and Following Google's Upload file data documentation for multipart uploads I have constructed this request body. I'm using the result of Filedrop's base64 as the binary file in my request body.

the file is upload to the correct folder and get the right name and the right type but I keep getting the "No preview available" when i open the image or PDF , i don't know which part of the request body is wrong...

Any support would be appreciated.

url and headers

--foo_bar_baz
Content-Type: application/json; charset=UTF-8

{'name': "{{filesDrop.files[0].name}}",'mimeType':'{{filesDrop.files[0].type}}','parents':['DRIVEID']}
--foo_bar_baz
Content-Type: {{filesDrop.files[0].type}}
Content-Transfer-Encoding: BASE64


{{filesDrop.value[0]}}//in base64 format

--foo_bar_baz--

1 Answers

let body = ""
let boundry = "--YOURBOUNDRY"
let rn = "\r\n"

// set file metadata
body += boundry + rn;
body += "Content-Type: application/json" + rn + rn;
body += "{\"name\":\"" + filesDrop.files[0].name + "\"}" + rn

// add actual file contents
body += boundry + rn;
body += "Content-Type: " + filesDrop.files[0].type + rn;
body += "Content-Transfer-Encoding: base64" + rn + rn; 
body += filesDrop.value[0] + rn;

body += boundry + "--";
return body;

Related