无法打开 CouchDB 附件

CouchDB Attachments Cannot be Opened

我从位于的文档开始 localhost:5984/categories/Jan 具有以下数据:

{
  "_id": "Jan",
  "_rev": "4-2c0b1c27daca6d2a3c375b0f879a8967",
  "name": "Jan",
}

我想上传一个pdf到这个文件,所以我给出了下面的curl命令:

curl -vX PUT 'http://localhost:5984/categories/Jan/example.pdf?rev=4-2c0b1c27daca6d2a3c375b0f879a8967' -d@example.pdf -H "ContentType: application/pdf"

我收到了这样的回复:

*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5984 (#0)
> PUT /categories/Jan/example.pdf?rev=4-2c0b1c27daca6d2a3c375b0f879a8967 HTTP/1.1
> Host: localhost:5984
> User-Agent: curl/7.47.0
> Accept: */*
> ContentType: application/pdf
> Content-Length: 10944067
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< Server: MochiWeb/1.0 (Any of you quaids got a smint?)
< Date: Thu, 11 Jan 2018 07:48:21 GMT
< Connection: close
* We are completely uploaded and fine
< HTTP/1.1 201 Created
< X-CouchDB-Body-Time: 0
< X-Couch-Request-ID: d509f366b8
< Server: CouchDB/2.1.1 (Erlang OTP/18)
< Location: http://localhost:5984/categories/Jan/example.pdf
< Date: Thu, 11 Jan 2018 07:48:23 GMT
< Content-Type: application/json
< Content-Length: 66
< Cache-Control: must-revalidate
<
{"ok":true,"id":"Jan","rev":"5-4ae0ca0bd54d63b9ac45e3e57785648d"}

在我看来这是一次成功的上传。但是,当我访问 url localhost:5984/categories/Jan/example.pdf,有两个问题:

除 pdf 之外的其他内容类型也会发生这种情况(我也尝试过使用 png)。任何人都可以让我知道可能出了什么问题吗?谢谢。

问题似乎是您在创建附件时指定的 ContentType header。

正确的header名字是Content-Type

curl 命令应该是:

curl -vX PUT 'http://localhost:5984/categories/Jan/example.pdf?rev=4-2c0b1c27daca6d2a3c375b0f879a8967' -d@example.pdf -H "Content-Type: application/pdf"