vokal / vip

Vokal Image Proxy is a lightweight image proxy designed for easy resizing and caching of images for mobile applications.
MIT License
2 stars 7 forks source link

can't seem to upload an image to vip... probably user error #112

Closed ne0zen closed 9 years ago

ne0zen commented 9 years ago

using the following cURL command

curl -X POST https://images.vokal.io/upload/vokalvip -H "content-type: image/png" -d @thing.png

thing.png is this: http://media.moddb.com/images/groups/1/6/5542/Derp_Derp_Derp.png

foresmac commented 9 years ago

You need to set the X-VIP-Token header. Try using the -v with curl so you can see the response code.

scottferg commented 9 years ago

@foresmac it actually crashes the server in that case so there's still something to fix here

foresmac commented 9 years ago

Well, that is awfully strange.

foresmac commented 9 years ago

I also think the header should be "Content-Type", but I'll def look into it.

foresmac commented 9 years ago

@ne0zen If you can post the verbose output from curl, that might be helpful.

ne0zen commented 9 years ago
rheflin@saffron ~$ curl -H "content-type: image/png" -H "X-Vip-Token: <redacted>" -d @thing.png https://images.vokal.io/upload/vokalvip -v
*   Trying 54.204.47.89...
* Connected to images.vokal.io (54.204.47.89) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_RC4_128_SHA
* Server certificate: *.vokal.io
* Server certificate: thawte SSL CA - G2
* Server certificate: thawte Primary Root CA
> POST /upload/vokalvip HTTP/1.1
> Host: images.vokal.io
> User-Agent: curl/7.43.0
> Accept: */*
> content-type: image/png
> X-Vip-Token: <redacted>
> Content-Length: 363372
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 502 Bad Gateway
< Server: nginx/1.8.0
< Date: Fri, 25 Sep 2015 18:43:43 GMT
< Content-Type: text/html
< Content-Length: 172
< Connection: keep-alive
<
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.8.0</center>
</body>
</html>
* Connection #0 to host images.vokal.io left intact
ne0zen commented 9 years ago

Re: header case,

Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive. --RFC2616

foresmac commented 9 years ago

@ne0zen Ok, looks like Go's net/http handles the header thing by making everything basically "title case", and that's how we grab those headers. I also uploaded the image to another service that uses VIP and it uploaded successfully:

screen shot 2015-09-25 at 2 09 50 pm

Finally, I tried uploading it myself using curl; here is the result:

$ curl -v -H "Content-Type: image/png" -H "X-Vip-Token: <REDACTED>" -X POST --data-binary @Derp_Derp_Derp.png https://images.vokal.io/upload/vokalvip
*   Trying 54.204.47.89...
* Connected to images.vokal.io (54.204.47.89) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_RC4_128_SHA
* Server certificate: *.vokal.io
* Server certificate: thawte SSL CA - G2
* Server certificate: thawte Primary Root CA
> POST /upload/vokalvip HTTP/1.1
> Host: images.vokal.io
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: image/png
> X-Vip-Token: <REDACTED>
> Content-Length: 760090
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 201 Created
< Server: nginx/1.8.0
< Date: Fri, 25 Sep 2015 19:13:21 GMT
< Content-Type: application/json
< Content-Length: 84
< Connection: keep-alive
< 
{"url":"http://images.vokal.io/vokalvip/03980f7e331d3de22760df3e78298721-844x1050"}
* Connection #0 to host images.vokal.io left intact

Served via VIP: Served via VIP

I think the difference is the --data-binary switch. I'm not sure why it returns a 502 when you don't use that, though. Definitely worth investigation more when I have the time.

ne0zen commented 9 years ago

TIL:

-d, --data is the same as --data-ascii. --data-raw is almost the same but does not have a special interpretation of the @ character. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data- urlencode.

--curl(1)

--data (and --data-ascii) strip newlines and carriage returns (handy when you're stuffing json from a file into a web service (my primary use-case for curl thus far) --data-raw (which doesn't support @filename) and --data-binary (which does) leave newlines and carriage returns alone.

foresmac commented 9 years ago

Right. Did you try with the --data-binary switch? Because that is what the server is expecting.

ne0zen commented 9 years ago

Yep! worked great!

foresmac commented 9 years ago

What I mean to say is, it's probably worth trying to detect if non-raw binary data is being passed in and try to return some meaningful error code if possible. Maybe the documentation can be updated to more explicitly spell out the expected data stream format and/or note a sample valid curl command.

ne0zen commented 9 years ago

I might file a doc-patch for vip with an example.

ne0zen commented 9 years ago

(at some future point)