Mashape image upload from localhost

229 views
Skip to first unread message

Vitaly S

unread,
Nov 2, 2014, 5:39:58 PM11/2/14
to im...@googlegroups.com
Trying to upload image from localhost with "TEST ENDPOINT":

But get an error:

HTTP/1.1 400 Bad Request
Access-Control-Allow-Headers: Authorization, Content-Type, Accept, X-Mashape-Authorization Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Connection: keep-alive Content-Length: 137 Content-Type: application/json Date: Sun, 02 Nov 2014 22:27:51 GMT Etag: "*************************************" Expires: Thu, 19 Nov 1981 08:52:00 GMT Pragma: no-cache Server: Mashape/5.0.5 X-Ratelimit-Requests-Limit: 12500 X-Ratelimit-Requests-Remaining: 12487 X-Ratelimit-Uploads-Limit: 1250 X-Ratelimit-Uploads-Remaining: 1238
{ "data": { "error": "Image format not supported, or image is corrupt.", "request": "/3/image", "method": "POST" }, "success": false, "status": 400 }

What I doing wrong? Checked the CURL from terminal, but without success.
When I uploading image from internet it works OK.

@jasdev

unread,
Nov 3, 2014, 2:54:29 PM11/3/14
to im...@googlegroups.com
Hey!

Are you trying to upload an image to the API via a URL?

If so, you have to make sure the URL is publicly available to our API can pick it up (which would explain why it worked on the server).

Let me know if this is not the case and I'd be glad to help further!

Cheers,

Jasdev

Vitaly S

unread,
Nov 8, 2014, 4:50:19 AM11/8/14
to im...@googlegroups.com
I trying to upload an Image from my local environment (as you can see in attache image, I using local path to image), like user that would be upload his image from his local environment to the imgur server. I tried the curl on local environment's terminal but without success.
Is it answers the question? Do I can add any more information to help you help me resolve the issue? :)

Thanks in advance 

@jasdev

unread,
Nov 8, 2014, 9:21:48 PM11/8/14
to im...@googlegroups.com
Got it!

So to curl an image up to the API locally via Mashape you'll need to actually POST the image data (since localhost URLs aren't publicly available). I've attached a sample request that you can try after filling in your credentials!

`curl -H "X-Mashape-Key: YOUR _MASHAPE_KEY "-H "Authorization: Client-ID YOUR_CLIENT_ID" -F "image=@/path/to/image" https://imgur-apiv3.p.mashape.com/`

Hope this helps!

Jasdev

Vitaly S

unread,
Nov 10, 2014, 6:18:23 AM11/10/14
to im...@googlegroups.com
Thank you for a response.

Tried your curl (with my MASHAPE_KEY and CLIENT_ID), it does return nothing :(, does it means that it works? How do I know the uploaded image url and other indormation?
Does Mashape Imgur API Documentation examples would work?


This One (not a local image url) is works OK for me (it is from Mashape Imgur API Documentation  Upload Image form):

curl -X POST --include "https://imgur-apiv3.p.mashape.com/3/image"   -H "X-Mashape-Key: YOUR _MASHAPE_KEY"   -H "Authorization: Client-ID YOUR_CLIENT_ID"   -H "Content-Type: application/x-www-form-urlencoded"   -d "image=https://www.google.co.il/images/srpr/logo11w.png"


But if I replace the https://www.google.co.il/images/srpr/logo11w.png with @/home/username/Desktop/1.jpg it returns: 

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

Do I miss something?

@jasdev

unread,
Nov 10, 2014, 3:09:56 PM11/10/14
to im...@googlegroups.com
Ah sorry typed in that cURL request a little too fast.

Here is the correct version:

`curl -H "X-Mashape-Key: MASHAPE_KEY" -H "Authorization: Client-ID CLIENT_ID" -F "image=@/path/to/image" https://imgur-apiv3.p.mashape.com/3/image`

Keep in ming there is a slight distinction between the -F and -d flags (http://curl.haxx.se/docs/manpage.html)

Vitaly S

unread,
Nov 11, 2014, 5:01:05 PM11/11/14
to im...@googlegroups.com
Thank you. Ok, this one returns the JSON with report and works OK (if someone need it)

curl -X POST --include "https://imgur-apiv3.p.mashape.com/3/image" -H "X-Mashape-Key: MashapeKey" -H "Authorization: Client-ID client_id" -F "image=@/home/username/Desktop/1.jpg"




But how do I upload local file with form in node.js?
I found this one 
unirest.post('http://httpbin.org/post')
.headers({ 'Accept': 'application/json' })
.field('parameter', 'value') // Form field
.attach('file', '/tmp/file') // Attachment
.end(function (response) {
  console
.log(response.body);
});

After adding relevant headers I got this one:

        unirest.post("https://imgur-apiv3.p.mashape.com/3/image")
           
.header("X-Mashape-Key", "MashapeKey")
           
.header("Authorization", "Client-ID client_id")
           
.header("Content-Type", "multipart/form-data")
           
.header('Accept', 'application/json' )
           
.field('parameter', 'value')
           
.attach('file', '/tmp/file')
           
.end(function (result) {
                console
.log(result.status, result.headers, result.body);
           
});

But something goes wrong, and I little bit confused:   

1. What is .field('parameter', 'value') - if I sendingthe request from standard html input, do I need to leave this part as is?
2. What is .attach('file', '/tmp/file') - Do I need to provide file path? How we do it if browsers security prevent this?
3. Is there simple working example for "Dummies" :) ?

Thanks in advance

Reply all
Reply to author
Forward
0 new messages