Tuesday, 14 March 2017

How to get image from couchbase?

I am doing a web site which has an admin side, the following is the code for creating an image attachment:

AttachmentModel.create=function(data,callback){

  var link = data.link;
  var fileName= data.name;
  var id= uuid();

  var options = {
    url: config.admin.url+'/'+id +'/'+fileName,
    method: "PUT",
    header:'Content-Type: image/png' 
};

fs.createReadStream(link).pipe(
    request(options, (err, response) => {
    })
)

callback(null,id);
};

And this is my code for getting attachment:

ModuleModel.getAttachment = function(id, name, sessionId, callback){
  var options = {
    url: config.sync.url+id+'/'+name,
    method: 'GET',
    headers: { 'Accept': 'image/png', "Cookie":sessionId }
  };

    request(options, function(error, response) {
        if(error){
            console.log("1"+error);
            return callback(error, null);
        }
           callback(null,response.body);
    });

}

This code returns strange characters like this : u����{�{�^���׺��u����{�{�^���׺��u����{�{�^���׺��u����{�{�^���׺��u����{�{�^���׺��u����{�{�^���׺��u���:M���� C��ߺ�Y}��u�~��Gc1{ B�up~�A`oϿu��� �,@:�����}�>]Q��u�2k!��ō������תf�d����3UO&�M���ll?>�ז��H���?��Ï~�λ���׽��u�~��{ߺ�^���׽��u�~��{ߺ�^���׽��u�~����

HELP PLEASE! I tried to convert that characters into base 64 then append as image with data:image/jpeg;base64,/9j/+characters but it didn't work.



via Emel Nacion

No comments:

Post a Comment