I am trying to send a PDF file as a base64 string to my drive folder using google drive API v3, but the only thing I get as a result is a file which displays the base64 string.
My code :
const boundary = '-------314159265358979323846';
const delimiter = "\r\n--" + boundary + "\r\n";
const close_delim = "\r\n--" + boundary + "--";
const metadata = {
'name': 'myFile.pdf',
'mimeType': 'application/pdf\r\n\r\n'
};
const multipartRequestBody = delimiter +
'Content-Type: application/json\r\n\r\n' +
JSON.stringify(metadata) +
delimiter +
'Content-Encoding: ' + 'base64\r\n' +
'Content-Type: ' + 'application/pdf\r\n\r\n' +
data +
close_delim;
const request = auth.request({
url: 'https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart',
method: 'post',
headers: {
'Content-Type': `multipart/related; boundary=${boundary}`,
'Content-Length': multipartRequestBody.length
},
data: multipartRequestBody
});
const response = await request;
I've searched everywhere, tried a lot of combinations but I am not able to make this work. Does anyone have an idea?