My Imgur upload function does not work without any reason.

Get help using Construct 2

Post » Sat May 31, 2014 6:38 pm

Hey Internet, I'm trying to upload a CanvasSnapshot to Imgur because they accept base64 data.

This is the error.
Code: Select all
{"data":{"error":"Image format not supported, or image is corrupt.","request":"\/3\/image","method":"POST"},"success":false,"status":400}


Following their examples and reading the API, I tried every single setup for the AJAX call.

Can you help me out?

My client ID is showing in the .capx, don't mind it; I will delete it anyway when this gets resolved.
Get yourself a client ID.
You do not have the required permissions to view the files attached to this post.
Last edited by sadNES on Sun Jun 01, 2014 3:10 pm, edited 1 time in total.
B
13
S
2
Posts: 27
Reputation: 952

Post » Sun Jun 01, 2014 12:44 pm

The same exact code works in jQuery, I don't know what seems to be the issue.
Last edited by sadNES on Tue Jun 03, 2014 9:03 pm, edited 1 time in total.
B
13
S
2
Posts: 27
Reputation: 952

Post » Mon Jun 02, 2014 7:34 pm

I'm dying.
B
13
S
2
Posts: 27
Reputation: 952

Post » Tue Jun 03, 2014 9:08 am

Set the POST data to:
Code: Select all
"type='base64'&image=" & URLEncode(RegexReplace(CanvasSnapshot, "data:image/png;base64,", "", ""))
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Tue Jun 03, 2014 9:03 pm

@ramones Thank you very much, I still don't understand why that syntax works and mine didn't... but that's how life goes, I guess,
B
13
S
2
Posts: 27
Reputation: 952

Post » Tue Jun 03, 2014 10:16 pm

The query string format for GET/POST requests is key-value pairs like key=value, separated by &, with + replacing any spaces.
parameter1=value1&parameter2=value2&parameter3=value+number+3

It looks like you were trying to use jQuery syntax. In jQuery you can pass an object { parameter1: value1, parameter2: value2 } which jQuery will convert into a query string like above.

And then the base64 encoded image could contain & or + or other characters that could be confused as part of the query string so you need to wrap it in URLEncode().
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650


Return to How do I....?

Who is online

Users browsing this forum: Elliott, kellehk, MadSpy, oosyrag, totoe, Yahoo [Bot] and 41 guests