I am trying to PUT my data within its attachment. I am doing it with NodeJS
Here is my code:
var date = new Date();
var data = {
name : obj.name,
serving : obj.serving,
cuisine : obj.cuisine,
uploadDate : date,
ingredients : obj.ing,
directions: obj.direction
} //Assume that I read this from html form and it is OK
db.insert(data, function(err, body){
if(!err){
console.log(body);
var id = body.id
var rev = body.rev
var headers = {
'Content-Type': req.files.image.type
};
var dataString = '@' + req.files.image.path;
var options = {
url: 'https://username:[email protected]/db_name/' + id + '/' + req.files.image.name +'?' + 'rev=' + rev,
method: 'PUT',
headers : headers,
body : dataString
}
console.log(options)
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
}
});
I am getting a 201 response after an image attachment has been sent. But in the cloudant dashboard I see "length": 38
of uploaded image which is impossible.
If I try to access uploaded image it gives:
{"error":"not_found","reason":"Document is missing attachment"}.
How I can fix this problem?