This getAttachment code works in Safari but not Chrome or Firefox.

16 views
Skip to first unread message

Bill Stephenson

unread,
Feb 23, 2017, 12:47:06 AM2/23/17
to PouchDB
Anyone have a clue what I'm doing wrong?


local_db.getAttachment(id, "atticPhoto").then(function (blob) {
console.log("SUCCESS getAttachment" +id);

var myImg = new Image();
myImg.onload = function() {
 var drawing = document.getElementById("landscape_canvas");
 var context = drawing.getContext("2d");
 context.save();
 context.drawImage(myImg, 0, 0);
};

var myUrl = URL.createObjectURL(blob);
myImg.src = myUrl;
// draw datalines
getDataLines(id);

 // handle result
}).catch(function (err) {
 console.log("getAttachment: " +err);
});


Chrome on my Mac gives this error:

pouchdb:api ambers_app +180ms getAttachment Array[1]0: "2017-02-22T17:12:31.114Z"length: 1__proto__: Array[0] atticPhoto
pouchdb-6.1.2.js:151 pouchdb:api ambers_app +254ms getAttachment error CustomPouchErrorerror: truemessage: "missing"name: "not_found"reason: "missing"status: 404__proto__: Error
 

Same thing in Firefox.

Safari has no problem:

[Log] pouchdb:api ambers_app +14ms (3) (pouchdb-6.1.2.js, line 151)
"getAttachment"
"success"
Blob {size: 234756, type: "image/jpg", slice: function}
[Log] SUCCESS getAttachment2017-02-22T17:12:31.114Z (imageDrawLandscape.js, line 77)
 

Bill Stephenson

unread,
Feb 23, 2017, 1:06:23 PM2/23/17
to PouchDB
Somedays I'm just dumber than a bag of mud. This code works, though I still don't know why the original code I was using did not.

local_db.get(id, {attachments: true}).then(function(doc) {
 console.log("SUCCESS GET DOC: " +id);  
}).then(function() {
 return local_db.getAttachment(id, image_id);
}).then(function (blob) {
 console.log("SUCCESS GET attachments: " +id);
 var myImg = URL.createObjectURL(blob);
 var myCanvas = document.getElementById('landscape_canvas');
 var ctx = myCanvas.getContext('2d');
 var img = new Image;
 img.onload = function(){
ctx.drawImage(img,0,0);
 };
 img.src = myImg;

}).catch(function (err) {
 console.log("ERROR getAttachment: " +err);
});
getDataLines(id);
Reply all
Reply to author
Forward
0 new messages