You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Anonymous One
2 years agoExplorer | Level 4
Upload file into Drop Box From NetSuite Using SuiteScript.
Hi,
I am trying to upload files from NetSuite into Drop Box using drop box upload API. I am able to upload text as well as CSV file but while uploading files like PDF,DOC,ZIP etc. I am able to upl...
Anonymous One
Explorer | Level 4
- the steps to reproduce the issue, including relevant code snippet(s), but don't include any access or refresh token(s)
- the full text of any error or unexpected output
(see my below reply in response to you query for uploading PDF)
1st try
let pdfData = file.load({
id: 'file cabinet file id'
}) // this will load the file
let dataContent = pdfData.getContents() // this will fetch the content of the loaded file.
let apiHeaders = {
"Authorization": `Bearer ${API_TOKEN}`,
"Dropbox-API-Arg": `{"path":"/Item Fulfillment/${pdfData.name}",
"mode":"add",
"autorename":false,
"mute":false
}`,
"Content-Type": "application/octet-stream"
} // header for the Drop Box API request
let responseData = https.post({
body: dataContent ,
url: API_URL,
headers: apiHeaders
})
In response I got code 200 PDF was uploaded in the DROP BOX but when I tried to Open the PDF got an error that '.PDF files are supported but something went wrong'.
Note - I tried same approach to upload CSV and TEXT file it worked but not working for files like PDF,DOC,ZIP etc.
2nd try
let binaryData = encode.convert({
string: pdfData.getContents(),
inputEncoding: encode.Encoding.BASE_64,
outputEncoding: encode.Encoding.UTF_8
});
(Here I tried same approach as above but tried to encode the data content and then sent it to DROP BOX)
Response - Got code 200. I was able to the open the PDF file but it was blank.
Здравко
2 years agoLegendary | Level 20
Anonymous One wrote:...let pdfData = file.load({id: 'file cabinet file id'}) // this will load the filelet dataContent = pdfData.getContents() // this will fetch the content of the loaded file....
Hi Anonymous One,
Are you sure the file denoted by the id is the actual file you want to upload and not some encoded form? You can ensure it as try to save this file (dataContent) on your server local place and fetch it using ftp (or similar method). Can you open properly such a file after that?! If you cannot do it, you cannot rely that such a file will be readable on Dropbox (it's the same file).
Anonymous One wrote:...let binaryData = encode.convert({string: pdfData.getContents(),inputEncoding: encode.Encoding.BASE_64,outputEncoding: encode.Encoding.UTF_8});...
As it has been mentioned already multiple times, the content you will try to upload must not be encoded in any way!!! If encoded somehow, you will get it in Dropbox encoded too. If the content is encoded in base64, transcoding it utf-8 just change one encoding to other and finally the content is still encoded (even more for binary files such encoding is destructive or can be at least). That's why such a move is incorrect definitely! For base64 encoded file you have to decode it, not transcode!!! Usually you can do it in a platform specific way (such tools are not JavaScript specific). In web browser environment, for instance, there is atob function that can do this. In nodejs, on other side, you can use Buffer class methods for the same. To be honest I'm not familiar to your environment, but there has to be something equivalent. If you don't know for such thing, ask your environment support. You can try implement such a decoding yourself if missing.
Hope this gives direction.
- Anonymous One2 years agoExplorer | Level 4
Hi Здравко
I mentioned in my earlier reply I tried 2 approach.
1st - Directly uploaded the file after reading the content of the file(which worked for CSV and TEXT file but for files like PDF,DOC,ZIP etc. file was uploading but wasn't even able to open it)
let pdfData = file.load({id: 'file cabinet file id'}) // this will load the filelet dataContent = pdfData.getContents() // this will fetch the content of the loaded file.let apiHeaders = {"Authorization": `Bearer ${API_TOKEN}`,"Dropbox-API-Arg": `{"path":"/Item Fulfillment/${pdfData.name}","mode":"add","autorename":false,"mute":false}`,"Content-Type": "application/octet-stream"} // header for the Drop Box API requestlet responseData = https.post({body: dataContent ,url: API_URL,headers: apiHeaders})2nd - When first approach didn't work I tried to encode it (file got uploaded in DROP BOX but it was blank).
let pdfData = file.load({id: 'file cabinet file id'}) // this will load the filelet dataContent = pdfData.getContents() // this will fetch the content of the loaded file.let binaryData = encode.convert({string: dataContent ,inputEncoding: encode.Encoding.BASE_64,outputEncoding: encode.Encoding.UTF_8});let apiHeaders = {"Authorization": `Bearer ${API_TOKEN}`,"Dropbox-API-Arg": `{"path":"/Item Fulfillment/${pdfData.name}","mode":"add","autorename":false,"mute":false}`,"Content-Type": "application/octet-stream"} // header for the Drop Box API requestlet responseData = https.post({body: dataContent ,url: API_URL,headers: apiHeaders})Здравко Regarding about if the file that I am loading is correct or not. I uploaded CSV and TEXT file using 1st approach it worked but for other files it didn't.
While loading the CSV file in NETSUITE default encoding for PDF and CSV file is same i.e. "UTF-8" but while uploading everything is fine with CSV but not with PDF upload.
- Здравко2 years agoLegendary | Level 20
Anonymous One, I have no idea how the situation can be explained more clear. Dropbox doesn't make difference between text based files and binary files! The content has to be uploaded as is without any change. Dropbox will save whatever you upload, as you have uploaded it, exactly (if encoded -> encoded)!!! That's why you cannot read it. Find a way to get to your files content non-encoded; it's the only way and usually there is such a way. For example CSV and TEXT files are... text!!! and that's why you are able see them, but PDF, DOC, and ZIP are not full text (in spite PDF and DOC are partially); in such files are least some binary pieces (non-representable as text), something that seems you cannot handle and as seems from your comment you're trying to pass in encoded form. All files you have passed (or will pass) in encoded form will not be readable. Do you understand the difference between text and binary file? Try to encode some ZIP file, locally on your machine, in base64 and see if this file will stay valid for the zip program you typically use. You can try transcode it to see if this helps. The same happens on your platform.
- Anonymous One2 years agoExplorer | Level 4
Hi Здравко ,
When I am trying to upload CSV and TEXT with same approach it is working but for PDF and other files which aren't text it is not working.
You mean for PDF I need to decode the data I am getting?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,888 PostsLatest Activity: 13 hours agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!