我試圖在附件中放入我的數據。我用的NodeJS將數據和附件放入Cloudant DB IBM bluemix
在這裏做這是我的代碼:
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);
}
});
我得到的圖像附件後201響應已發送。但在雲端儀表板中,我看到上傳圖像的"length": 38
這是不可能的。
如果我試圖訪問它給上傳的圖片:
{ 「錯誤」: 「NOT_FOUND」, 「原因」: 「找不到文件附件」}。
我該如何解決這個問題?