使用 cURL 创建 couchdb 独立附件
我目前正在使用 couchdb 并测试“独立附件”功能,该功能在此页面底部附近进行了描述。
我正在尝试使用curl的--data-urlencode功能来发送创建请求,但这只起作用了一半。我可以创建附件并检索它,但内容类型字段错误,因此图像无法正确显示。
更准确地说,CouchDB 似乎通过使用发布的相同内容类型返回附件来工作。(在我看来,这是完全明智的)我的问题是curl 没有发送正确的代码。这是详细信息;
curl -vX PUT http://localhost:5984/dafttest/666/attachment --data-urlencode image/jpeg@xi_on_beach.jpg
* About to connect() to localhost port 5984 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 5984 (#0)
> PUT /dafttest/666/attachment HTTP/1.1
> User-Agent: curl/7.19.4 (x86_64-pc-linux-gnu) libcurl/7.19.4 OpenSSL/0.9.8k zlib/1.2.3
> Host: localhost:5984
> Accept: */*
> Content-Length: 495389
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
所以这个问题的简短版本是;如何让 cURL 发送正确的 Content-Type ?
编辑:
我发布我的另一个错误是使用 --data-urlencode,当要让它工作时我需要使用 --data 二进制 @filename 以及 Dale 建议的 -H 选项。
I am currently playing with couchdb and testing out the 'standalone attachments' feature, which is described near the bottom of this page.
I am trying to use curl's --data-urlencode feature to send the creation request, which only half works. I can create the attachment and retrieve it, but the Content-Type field is wrong, so the image won't display correctly.
To be more accurate CouchDB seems to work by returning the attachment using the same Content-Type it was posted in. (which is perfectly sensible IMO) My problem is curl doesn't send the correct code. Here's the details;
curl -vX PUT http://localhost:5984/dafttest/666/attachment --data-urlencode image/jpeg@xi_on_beach.jpg
* About to connect() to localhost port 5984 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 5984 (#0)
> PUT /dafttest/666/attachment HTTP/1.1
> User-Agent: curl/7.19.4 (x86_64-pc-linux-gnu) libcurl/7.19.4 OpenSSL/0.9.8k zlib/1.2.3
> Host: localhost:5984
> Accept: */*
> Content-Length: 495389
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
So the short version of this question is; how to I get cURL to send the correct Content-Type ?
EDIT:
I release that my other mistake was to use --data-urlencode, when to get it to work I need to use --data binary @filename together with the -H option that Dale suggested.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 -H/--header 开关添加标头,以便添加标头对于 image/jpeg 内容类型,请将其添加到您的命令中:
You can add headers with the -H/--header switch, so to add a header for image/jpeg content type, add this to your command: