Announcements
Can you spare 5 minutes to help us improve our online support experience? Get involved!

File upload error code 500

Explorer | Level 3

I am trying to upload a PDF in my javascript file but i get server response error code 500. I also need to find what i have to put in the body to upload the pdf file (using netsuite so i cant use the dropbox-sdk). I am now encoding my pdf from Base64 (that is what it is on my server) and outputEncoding is UTF-8 does this work>

function uploadFile(key, path, file) {

    var URL = 'https://content.dropboxapi.com/2/files/upload';

//converting my file from base_64 to UTF_8
    var body = encode.convert({
      string: file,
      inputEncoding: encode.Encoding.BASE_64,
      outputEncoding: encode.Encoding.UTF_8
    });

//header for Dropbox
    var headers = {
      "Authorization": 'Bearer '+ key,
      "Dropbox-API-Arg":{"path":"/home/1.pdf","mode":"add","autorename":true,"mute":false,"strict_conflict":false},
      "Content-Type": "application/octet-stream",
    };
    
//netsuite specific
    log.debug({
      title: "debug",
      details: body
    });

//the post to https
    var response = https.post({
      url: URL,
      body: body,
      headers: headers
    });

//below function is netsuite specific
    log.debug({
      title: 'Dropbox server response',
      details: JSON.stringify(response)
    });



  }
5 Replies

Re: File upload error code 500

Dropboxer

When uploading data to a Dropbox API "content-upload" style endpoint, such as /2/files/upload, you should send the raw bytes in the request body as an "application/octet-stream". 

If you're getting a 500 Internal Server Error back, please share a few sample "x-dropbox-request-id" response header values so we can look into it. Thanks in advance! 

Reply
Loading...

Re: File upload error code 500

Explorer | Level 3
{
   type: "http.ClientResponse",
   code: 500,
   headers: {
      "Transfer-Encoding": "chunked",
      "X-Dropbox-Request-Id": "d7032e53a533fb8505ea7d99debf3fa3",
      "X-Robots-Tag": "noindex, nofollow, noimageindex",
      Server: "nginx",
      "Content-Security-Policy": "sandbox allow-forms allow-scripts",
      Date: "Mon, 14 Oct 2019 15:10:42 GMT",
      "Content-Type": "text/plain; charset=utf-8",
      Via: "1.1 mono003"
   },
   body: ""
}

This is what i got back when trying to upload a file by the code from the original post. 

Reply
Loading...

Re: File upload error code 500

Dropboxer

Thanks! It looks like the Dropbox API is having trouble parsing this particular request. Can you print out and share the raw HTTP request, including headers? That should help us reproduce and debug this. (Be sure to redact your access token, and the request body if it's private, of course.) Thanks in advance.

Reply
Loading...

Re: File upload error code 500

Explorer | Level 3
"Authorization": 'Bearer '+ key,
      "Dropbox-API-Arg":{"path":"/home/yes.pdf","mode":"add","autorename":true,"mute":false,"strict_conflict":false},
      "Content-Type": "application/octet-stream"

Above the header i am giving.

URL i am using is: 

https://content.dropboxapi.com/2/files/upload  

 Here is the pdf from base_64 to utf_8 (partly) 

%PDF-1.3
%����
1 0 obj
<</Type/Catalog/Pages 4 0 R/Lang(en-US)/Names 3 0 R/Metadata 5 0 R>>
endobj
2 0 obj
<</Producer(http://bfo.com/products/report?version=1.1.61-r25714)/CreationDate(D:20180703053256-07'00')/ModDate(D:20180703053256-07'00')>>
endobj
3 0 obj
<</Dests 6 0 R>>
endobj
4 0 obj
<</Type/Pages/Kids[7 0 R]/Count 1>>
endobj
5 0 obj
<</Type/Metadata/Subtype/XML/Length 875>>stream
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<xface without mouthmpmeta xmlnsface without mouth="adobe:ns:meta/" xface without mouthmptk="BFOXMP 1.1.61-r25714"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description xmlns:pdf="http://ns.adobe.com/pdf/1.3/" rdf:about=""><pdf:Producer>http://bfo.com/products/report?version=1.1.61-r25714</pdf:Producer></rdf:Description><rdf:Description xmlnsface without mouthmp="http://ns.adobe.com/xap/1.0/" rdf:about=""><xmp:CreateDate>2018-07-03T05:32:56-07:00</xmp:CreateDate><xmp:ModifyDate>2018-07-03T05:32:56-07:00</xmp:ModifyDate><xmp:MetadataDate>2018-07-03T05:32:56-07:00</xmp:MetadataDate></rdf:Description><rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about=""><dc:date><rdf:Seq><rdf:li>2018-07-03T05:32:56-07:00</rdf:li></rdf:Seq></dc:date><dc:format>application/pdf</dc:format></rdf:Description></rdf:RDF></xface without mouthmpmeta>
<?xpacket end='r'?>
endstream
endobj
6 0 obj
<</Names[(page1)8 0 R]>>
endobj
7 0 obj
<</Type/Page/MediaBox[0 0 612 792]/Resources<</ColorSpace<</DefaultRGB 12 0 R>>/ProcSet[/PDF/ImageI/Text/XObject]/XObject<</R1 11 0 R/R3 13 0 R>>/Font<</R2 14 0 R/R4 16 0 R>>>>/Contents[9 0 R]/Parent 4 0 R/Annots 10 0 R>>
endobj
8 0 obj
<</Type/Action/S/GoTo/D[7 0 R/XYZ 0 792 0]>>
endobj
9 0 obj
<</Filter/FlateDecode/Length 1748>>stream
x��X�r�6 }�W`�� iF�q'اZ�z��$���!� #��b�TH�n�Q�� ��� i��1E��ݳg/X�kO F a�Ӝ*Ƙ$�SCL �ٺwv���Y��xڛL�� aNT�( �D�QK�� �_ܑ�] "����>���� $�|0R�_��_�W�J#C�UjYD���k�Z���|��������l]/�2�M,�6&ڭg (�I�]�0ЬO�Yt& ����i �ә�<@ >�������K � ����W��_����HCDDc� �r�f#���, �n+ =چ2 �(�T ��ۛ�)�nIx�9�<�cӼ�m��� ��(QA��|� ����������ڑ��`�$��S� ��ø{�q�� 4䗁��ܹ;2v��2]$A ## %�6]� 8�m�i�� >< , ���AAlm�hdcr VM�o�e1�b�vH�ɲ|>�-[��t�摔T� ������u�rI�Ȼ<��f% {J�{ �}��ǫ�Z� rۼج�2%Bt�� A? G�,s7�\vAws��\�w�!$8� �Ah2Z'�U��A 5�4�c�$�2
Y��XTN
���� <z�>r�C��OŲt��
Reply
Loading...

Re: File upload error code 500

Dropboxer

The "content-upload" style endpoints such as /2/files/upload just expect the binary in the request body so you shouldn't have to re-encode the file data after decoding it from base64. In any case, as far as I can tell from our side, the issue here is with parsing the "Dropbox-API-Arg" header, not the body, so that shouldn't be relevant here.

I see you shared the values you're setting, but can you share the actual raw HTTP request headers as they're being sent?

Reply
Loading...
API Support

Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.

Not the right discussion for you? Find out what else our Community has to say about API Support.

Or, search our Help Center for even more.

Who's talking
Top contributors to this post