CouchDB attachments cannot be opened

I start with a document located in localhost:5984/categories/Jan with the following data:

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

I want to load a pdf document into this document, so I give the following curl command:

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

And I get this answer:

 * 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"} 

It seems to me that this is a successful download. However, when I visit the localhost:5984/categories/Jan/example.pdf url localhost:5984/categories/Jan/example.pdf , there are two problems:

  • instead of opening in a browser, I’ll be asked to download an attachment
  • When I download and open the attachment, it says that the data cannot be read.

This happens for content types other than pdf files (I also tried w / png). Can someone tell me what could be wrong? Thanks.

+5
source share
1 answer

The problem is that the ContentType header that you specified when creating the attachment.

The correct Content-Type header name

The curl command should be:

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

Source: https://habr.com/ru/post/1274626/


All Articles