Search code examples
pushbullet

Upload: 500 Internal Server Error


To anyone stumbling upon this: this is in regard to the Pushbullet API, as tagged.

Trying this for the first time.

I seem to have a good response to my Upload Request, and I'm pretty sure I have the correct Upload URL for this, but the Upload stage keeps failing on me.

Code is VB6 using an MSXML2.XMLHTTP instance for sending:

With XMLHTTP
    .open "POST", UploadUrl, True
    .setRequestHeader "Access-Token", AccessToken
    .setRequestHeader "Content-Type", "multipart/form-data; boundary=" & ContentBoundary
    .onreadystatechange = Me
    .send MultipartFormBody
End With

MultipartFormBody is a Byte array so nothing is getting transcoded into UTF-8 there. ContentBoundary is a String generated in tandem with the body data. UploadUrl is a String with a value returned in the immediately prior (Upload Request) response. XMLHTTP creates a Content-Length header automagically.

As far as I can see the message body is properly formatted too. When I had a flaw in the latter I got back an error message that was quite helpful in correcting it.

--PushbulletReporter_3E43228zZz82234E3{CRLF}
Content-Disposition: form-data; name="file"; filename="capture.png"{CRLF}
Content-Type: image/png{CRLF}
{CRLF}
{bytes of a PNG image}--PushbulletReporter_3E43228zZz82234E3--{CRLF}

But now I get a 500 Internal Server Error with an error message "An unhandled server error occurred."

The body is a hair under 3.5KB. I'm down to notions like... perhaps chunked encoding is required here?

Any clues? What more information might help?


Solution

  • First I want to apologize for that file upload thing, multipart/form-data is regrettably hard to actually create since few languages have standard libraries that do this. I have a version where you just upload the bytes directly, but it's not quite ready to be released yet.

    I see some "unexpected EOF" errors in the logs, so I can only assume that that is what is going on here. I haven't run any tests yet, but I think you don't have enough {CRLF}s in there or some other minor error. If you could create the encoded data with an existing library then compare it to your output, that would be ideal.

    I'll try to make the server return a 400 in this case, but I imagine it will be "Invalid multipart body".

    I made a test script, and it looks like the missing CRLFs is the problem:

    --d3880c80febbef19d78c6daf83da33d6b973d2524d9a6146e4bc71f4973b\r\nContent-Disposition: form-data; name=\"file\"; filename=\"filename\"\r\nContent-Type: application/octet-stream\r\n\r\n{bytes of a PNG image}\r\n--d3880c80febbef19d78c6daf83da33d6b973d2524d9a6146e4bc71f4973b--\r\n
    

    Note the CRLF after the bytes of the PNG image part, I think you are missing those