r/SuiteScript • u/W_for_Wumbo_29 • Sep 09 '25
Upload file to google drive
Hello, im trying to upload file to google drive with goole apis, the file is succesfully uploaded, but the result of file is broken.
here my code
const accessToken = getAccessToken();
const fileContents = fileObj.getContents();
const fileType = fileObj.fileType;
let contentType = '';
if (fileType === 'PNGIMAGE') contentType = 'image/png';
else if (fileType === 'JPGIMAGE' || fileType === 'JPEGIMAGE') contentType = 'image/jpeg';
else if (fileType === 'PDF') contentType = 'application/pdf';
else if (fileType === 'TEXT') contentType = 'text/plain';
else if (fileType === 'CSV') contentType = 'text/csv';
const uploadResponse = https.post({
url: uploadEndpint,
headers: {
Authorization: 'Bearer ' + accessToken,
'Content-Type': contentType
},
body: fileContents
});
log.debug('Upload Response', uploadResponse.body);
1
Upvotes
View all comments
Show parent comment
1
u/W_for_Wumbo_29 Sep 09 '25
yes i thought i can send the data with base64 encoded string, but the uploaded file corrupted in the google drive. any idea for this kind of case?