Reputation: 53
While uploading pictures using the Imgur API, some pictures are not uploaded and returns status 400 or 417 errors.
{
status: 400,
success: false,
data: {
error: "We don't support that file type!",
request: '/3/upload'
}
{
status: 417,
success: false,
data: {
error: 'Internal expectation failed',
request: '/3/upload',
method: 'POST'
}
}
This error was fixed upon launching the console. But every time I upload a picture I have to restart the console. How may I prevent this from happening?
Upvotes: 4
Views: 2991
Reputation: 3885
Note: Your "Account" and your "Application" are distinct entities. If you try to upload to an album on your account, thinking your application has access rights to it because they are tied to the same email, you'll probably get the 417 error.
Also, it seems that imgur validates the .PNG file before validating access rights.
I have concluded that as you are trouble shooting , this is a rough gauge of "how close to success" you are:
1: VERY CLOSE : "Internal Expectation Failed" Your .PNG payload within the form-data is probably correct.
2: COLDER : "We Don't Support That File Type" You probably corrupted your .PNG binary file when attempting to concat it into the "form-data" payload.
3: COLDEST : "bad request" You messed up real bad.
If you are rolling your own "multi-part form-data" like I did, one of the posters here has a good low-level example that does NOT use 3rd party libraries: NodeJS Request how to send multipart/form-data POST request
Your payload is constructed something like this:
payload=Buffer.concat([
Buffer.from( formdata_string_top , "utf8" )
, Buffer.from( png_binary_file , "binary" )
, Buffer.from( final_formdata_boundary, "utf8" )
]);;
You might be tempted to do this , because it is readable in your logs, but it WILL_CORRUPT_YOUR_BINARY_FILE
payload=Buffer.concat([
Buffer.from( formdata_string_top , "utf8" )
, Buffer.from( png_binary_file , "binary" )
, Buffer.from( final_formdata_boundary, "utf8" )
]).toString( "utf8" );
Upvotes: 1
Reputation: 2286
The 417 error states that the Imgur CDN was expecting a file type such as .png, .mp4, .gif, etc. You may view the supported file types here.
The 400 indicates an improper / bad request , while requesting the API for a POST
type request you must know how to properly request it, you may refer to the proper method here.
Upvotes: 4