I'm bulk-uploading documents to a CouchDB with a System.Net.WebClient like this:
webClient.UploadString("couchdb.host.com:5984/db/_bulk_docs", "POST", json_data);
This usually works fine, but sometimes I get a WebException with a 'Bad Request' Status (400). Unfortunately, that's the only information I get, so I don't really know what causes the exception.
I checked the logfiles under /var/log/couchdb/couchdb.log, but I did not get any further info there:
[notice] 2019-09-10T15:26:09.173949Z couchdb@host.com <0.5318.568> f50ab02d22 host.com:5984 x.x.x.x undefined POST /db/_bulk_docs 400 ok 75
So my questions are:
Is there more information hidden somewhere in the WebException object and if so, where do I find it?
is there a way to get more informations on the server side?
My suspicion is that the documents I am trying to upload, are too big. How can I check that?
Update:
I dumped the faulting request into a file with:
catch (WebException ex)
{
File.WriteAllText("C:\\temp\\couchdb_bad_request.json", json_data);
}
and tried it again with:
curl -X POST http:/couchdb.host.com:5984/db/_bulk_docs -H "Content-Type: application/json" -d @couchdb_bad_request.json
This time I got a 201. So what's the difference between a curl and a WebClient request?
My json data look like this:
{
"docs": [
{
"Type": "Image",
"_attachments": {
"123_original.jpg": {
"content_type": "image/jpeg",
"data": "<base64-encoded image data>"
}
},
"ID": "123",
"_id": "123",
"FileName": "some_file.jpg",
"AttachmentMetaData": {
"original": {
"Width": 864,
"Height": 576,
"MD5Checksum": "a20ecae8e3a7df8cc8558a71efc2b573"
}
}
},
{...}
]
}