I am trying to upload files from NetSuite into DropBox using Suite Script. I am able to upload text and csv files successfully but for files like PDF,DOC,ZIP (binary files). I am unable to upload it directly. I am trying to upload native NetSuite transaction PDF (I tried to upload a PDF downloaded from google and I worked by encoding it from BASE_64
to UTF_8
.).
For CSV I tried
let loadFileObj = file.load({
id: 'file Cabinet File Id'
})
let apiHeaders = {
"Authorization": `Bearer ${API_TOKEN}`,
'Content-Type': 'application/octet-stream',
"Dropbox-API-Arg": `{"path":"/Item Fulfillment/${loadFileObj.name}",
"mode":"add",
"autorename":false,
"mute":false
}`,
"Content-Transfer-Encoding": "BINARY"
}
let responseData = https.post({
body: loadFileObj .getContents(),
url: API_URL,
headers: apiHeaders
})
FOR PDF TRIED SAME APPROACH DIDN'T WORK.TRIED TO ENCODE IT FROM BASE64
TO UTF8
FILE GET UPLOADED WHEN TRIED TO OPEN IT IT WAS BLANK.
I CHECKED DROPBOX API DOC THERE IT IS MENTIONED DATA SHOULD BE BINARY DATA I TIRED TO CONVERT IT INTO BINARY BUT IT DIDN'T HELP.
I TRIED TO PASS PARAMETER Content-Transfer-Encoding
IN HEADER IT DIDN'T WORK. CAN SOMEONE PLEASE HOW TO UPLOAD PDF FILES AS BINARY DATA INTO DROPBOX.