<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to encode/decode correctly using NetSuite file upload in Suitelet in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/558591#M26411</link>
    <description>&lt;P&gt;Hi What should i pass in headerObj?&lt;/P&gt;</description>
    <pubDate>Fri, 19 Nov 2021 07:14:35 GMT</pubDate>
    <dc:creator>pradikrish</dc:creator>
    <dc:date>2021-11-19T07:14:35Z</dc:date>
    <item>
      <title>How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406293#M22096</link>
      <description>&lt;P&gt;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. However, I can't figure out how to get the file contents to set correctly. Currently, the file is being created with the some sort of encoding/decoding like this "&lt;SPAN&gt;UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here's the code:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 *@NModuleScope Public
 */
define(['N/ui/serverWidget', 'N/file', 'N/https', 'N/encode'],
    function(serverWidget, file, https, encode) {
        function onRequest(context) {
            if (context.request.method === 'GET') {
                var form = serverWidget.createForm({
                    title: 'Upload Artwork',
                    hideNavBar: false
                });

                // Add File Upload
                var fileFld = form.addField({
                    id: 'custpage_file',
                    type: serverWidget.FieldType.FILE,
                    label: 'Upload File'
                });
                form.addSubmitButton({
                    label: 'Upload'
                });
                context.response.writePage(form);
            } else {
                // 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 = toBase64(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
                });

                // Write Response
                context.response.write(JSON.stringify(res));
            }
        }
        function toBase64(stringInput){
            return encode.convert({
                string: stringInput,
                inputEncoding: encode.Encoding.UTF_8,
                outputEncoding: encode.Encoding.BASE_64
            });
        }
        return {
            onRequest: onRequest
        };
    });&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 05:59:51 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406293#M22096</guid>
      <dc:creator>jmbrox</dc:creator>
      <dc:date>2020-04-03T05:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406299#M22097</link>
      <description>&lt;P&gt;In your code, I see you're uploading the data in the 'decodedStr', which is defined via 'var decodedStr = toBase64(fileContents);'. That seems like it may be the opposite of what you want to do though. The&amp;nbsp;Dropbox API does not expect the uploaded data to have a layer of base64 encoding and will not automatically undo any such layer set by the client. Further, it looks like the original contents in 'fileContents' may already be base64-encoded, so "toBase64" may be the wrong thing to do anyway. Did you perhaps mean to implement and use a "fromBase64" instead? (That would also make more sense given the variable name 'decodedStr'.)&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:14:09 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406299#M22097</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-04-02T17:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406339#M22101</link>
      <description>&lt;P&gt;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 &amp;lt;input&amp;gt; but through NetSuite's N/file module/object.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 18:57:42 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406339#M22101</guid>
      <dc:creator>jmbrox</dc:creator>
      <dc:date>2020-04-02T18:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406341#M22102</link>
      <description>&lt;P&gt;I was able to get a .rtf to upload with the correct contents (simple text phrase: "This is text") using the following:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;// 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
            });
        }&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 19:08:14 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406341#M22102</guid>
      <dc:creator>jmbrox</dc:creator>
      <dc:date>2020-04-02T19:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406358#M22104</link>
      <description>&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_self"&gt;The&amp;nbsp;/2/files/upload endpoint&lt;/A&gt; is a &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#formats" target="_self"&gt;"content-upload" style&lt;/A&gt; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't offer help with working in&amp;nbsp;NetSuite though, as it's made by a third party, so I don't know how data retrieval/handling works there.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 20:24:47 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/406358#M22104</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-04-02T20:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/558591#M26411</link>
      <description>&lt;P&gt;Hi What should i pass in headerObj?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 07:14:35 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/558591#M26411</guid>
      <dc:creator>pradikrish</dc:creator>
      <dc:date>2021-11-19T07:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/558718#M26418</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1494079"&gt;@pradikrish&lt;/a&gt; You can find the expected headers and parameters for any given API endpoint in &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation" target="_self"&gt;the API documentation&lt;/A&gt;. For example, &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_self"&gt;here is the documentation for /2/files/upload&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 16:56:16 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/558718#M26418</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-11-19T16:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/698185#M31182</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 06:32:59 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/698185#M31182</guid>
      <dc:creator>Anonymous One</dc:creator>
      <dc:date>2023-07-12T06:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to encode/decode correctly using NetSuite file upload in Suitelet</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/698288#M31185</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1724855"&gt;@Anonymous One&lt;/a&gt; I see you also posted &lt;A href="https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-file-into-Drop-Box-From-NetSuite-Using-SuiteScript/td-p/698184" target="_blank"&gt;your own thread&lt;/A&gt;, so we'll follow up with you there.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 15:19:52 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-encode-decode-correctly-using-NetSuite-file-upload-in/m-p/698288#M31185</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-07-12T15:19:52Z</dc:date>
    </item>
  </channel>
</rss>

