Issue adding attachments to documents in CouchDB

I'm having problems adding attachments in CouchDB. First off, when I ran the test suite in Futon I got two errors - one in attachments, and another in replication. The error specific to attachments isn't particularly helpful -

name
    attachments
status
    error
duration
    6112
details
    0
    Exception raised: {}

Some internet commentary says that a few errors in the test suite is perfectly normal, so I moved on. However, attachments are definitely not working properly, either via Futon or Curl. In Futon, the file will generally attach, but only after I click cancel on the upload - ie it hangs on the upload progress bar indefinitely until I click cancel. I'm accessing futon on a remote machine via ssh -L5984:127.0.0.1:5984 root@myServer and then pointing Firefox at localhost:5984/_utils/. I don't know if that could be making a difference.

When I try to upload via Curl, using the command

curl -vX PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/ artwork.jpg?rev=9--43332bfae07884c683b50ffd4b8ee18c --data-binary @artwork.jpg -H "Content-Type: image/jpg"

I get:

Host: 127.0.0.1:5984 Accept: / Content-Type: image/jpg Content-Length: 11205 Expect: 100-continue

< HTTP/1.1 100 Continue
< HTTP/1.1 400 Bad Request
* HTTP error before end of send, stop sending
{"error":"bad_request","reason":"invalid UTF-8 JSON"}

The log file shows:

[debug] [<0.103.0>] 'PUT' /albums/6e1295ed6c29495e54cc05947f18c8af/ {1,1}
Headers: [{'Accept',"*/*"},
      {'Content-Length',"11205"},
      {'Content-Type',"image/jpg"},
      {"Expect","100-continue"},
      {'Host',"127.0.0.1:5984"},
      {'User-Agent',"curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3"}]

[debug] [<0.103.0>] OAuth Params: []

[error] [<0.103.0>] attempted upload of invalid JSON (set log_level to debug to log it)

Followed by a huge block -

[debug] [<0.103.0>] Invalid JSON:   
<<255,216,255,224,0,16,74,70,73,70,0,1,1,0,0,1,0,1,0,0,255,219,0,132, ... , etc

The final two lines in the log that are relevant to the attempted upload are

[info] [<0.103.0>] 127.0.0.1 - - 'PUT' /albums/6e1295ed6c29495e54cc05947f18c8af/ 400
[debug] [<0.103.0>] httpd 400 error response: {"error":"bad_request","reason":"invalid UTF-8 JSON"}

Does anyone have any idea what is going on here? I tried wrapping the string in the curl request around ' ' in case bash was eating the quotes, it made no difference.


There is a spurious space in your curl command after the slash between the doc id and the attachement:

...f18c8af/ artwork.jpg?...
           ^

Does it work when you remove it?


There were two problems. The first was the spurious space that Simon pointed out - tyvm. The other problem was where the rev-x details are placed. I was using the format in the book http://guide.couchdb.org/editions/1/en/api.html.

Original command:

curl -vX PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/ artwork.jpg?rev=9--43332bfae07884c683b50ffd4b8ee18c --data-binary @artwork.jpg -H "Content-Type: image/jpg"

Working command (space removed & rev placed in the correct order):

curl -vX PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/attachment?rev=9-43332bfae07884c683b50ffd4b8ee18c --data-binary @artwork.jpg -H "Content-Type: image/jpg"
链接地址: http://www.djcxy.com/p/48550.html

上一篇: 我应该放置我的json文件的目录,以便将其导入到couchdb中

下一篇: 问题添加附件到CouchDB中的文档