Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
jmbrox
6 years agoExplorer | Level 3
How to encode/decode correctly using NetSuite file upload in Suitelet
I'm trying to use NetSuite's N/file module to upload a file to DropBox. I've been successful at authentication, getting a 200 when submitting the POST request to Create FolderV2 and Upload File. Howe...
jmbrox
6 years agoExplorer | Level 3
Thanks for the response. I've actually tried both ways. Can you point me to the correct format needed for the body of the request? I've been attempting to find an example for some time but all I can find is data-binary: @filename.docx. I'm looking for how to add the body value without referencing the file from an <input> but through NetSuite's N/file module/object.
jmbrox
6 years agoExplorer | Level 3
I was able to get a .rtf to upload with the correct contents (simple text phrase: "This is text") using the following:
// Getting File from NS File Field
var fileObj = context.request.files['custpage_file'];
// Setting Folder in File Cabinet
fileObj.folder = 214960;
var fileId = fileObj.save();
// Getting/Logging File Contents
var fileContents = fileId.getContents();
log.debug({title: 'File Contents', details: fileContents});
// File Contents = UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAA
// Decode the String
var decodedStr = fromBase64(fileContents);
log.debug({title: 'Decoded Contents', details: decodedStr});
var headerObj = {};
// Upload Request
var res = https.request({
method: https.Method.POST,
url: 'https://content.dropboxapi.com/2/files/upload',
body: decodedStr,
headers: headerObj
});
function fromBase64(stringInput){
return encode.convert({
string: stringInput,
inputEncoding: encode.Encoding.BASE_64,
outputEncoding: encode.Encoding.UTF_8
});
}
However, .docx and .pdf are not uploading with any content. Are those supposed to be in UTF_8 as well? Are there differences between the types of files. I'm just looking to upload .ai and .pdf file formats.
- Greg-DB6 years ago
Dropbox Community Moderator
The /2/files/upload endpoint is a "content-upload" style endpoint, meaning it expects the raw file data to be sent in the HTTPS request body, with the "Content-Type: application/octet-stream" request header to match.
I can't offer help with working in NetSuite though, as it's made by a third party, so I don't know how data retrieval/handling works there.
- pradikrish5 years agoNew member | Level 2
Hi What should i pass in headerObj?
- Greg-DB5 years ago
Dropbox Community Moderator
pradikrish You can find the expected headers and parameters for any given API endpoint in the API documentation. For example, here is the documentation for /2/files/upload.
- Anonymous One3 years agoExplorer | Level 4
Hi,
Did you find how to upload PDF,DOC,ZIP etc. I am also facing same issue, able to upload CSV and TEXT file successfully but stuck for other files.
- Greg-DB3 years ago
Dropbox Community Moderator
Anonymous One I see you also posted your own thread, so we'll follow up with you there.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If 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, Facebook or Instagram.
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!