Closed ne0zen closed 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.
@foresmac it actually crashes the server in that case so there's still something to fix here
Well, that is awfully strange.
I also think the header should be "Content-Type", but I'll def look into it.
@ne0zen If you can post the verbose output from curl, that might be helpful.
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
Re: header case,
Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive. --RFC2616
@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:
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:
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.
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.
Right. Did you try with the --data-binary
switch? Because that is what the server is expecting.
Yep! worked great!
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.
I might file a doc-patch for vip with an example.
(at some future point)
using the following cURL command
thing.png is this: http://media.moddb.com/images/groups/1/6/5542/Derp_Derp_Derp.png