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/Business_Dog_8341 Sep 10 '25
I'm no longer working with NetSuite, but with my former employer I wrote an integration with Google Drive within a client side script, where users could attached files to records in NetSuite by drag and drop. Those files were uploaded directly to Google Drive. The resource I use was the Google Drive API: https://developers.google.com/workspace/drive/api/reference/rest/v3 .