خرید بک لینک

Vote count: 0

Scenario:

I have to send user file which is stored remotely in a server(cloudinary) to browser. I'm able to request an image from server and then pipe it to browser but it's not working for other files like pdf, excel sheet, etc.

exports.fetchFile = function(req, res, next){ var fileUrl = "/" + req.params.fileUrl; console.log(fileUrl);

async.auto({
    'A': function(callback) {
        var queryObj = { 'myUrl' : fileUrl};
        // DB Query to retrieve user file information like url, type, etc.
        UserFileCtrl.fetchUserFile(queryObj, callback);
    }
}, function(err, results){
    if(err) {
        retu res.send(500, "error");
    }

    var secureUrl = results['A']['secureUrl'];
    var fileType = results['A']['fileType'];
    // this will be "application/pdf" for pdf
    res.setHeader('Content-Type', fileType);

    request(secureUrl).pipe(res);
}); 

}

Above code gives an empty pdf file to client whereas if I open directly the cloudinary url then it's coming properly. I'm breaking my head for a long time but not able to get something out of it.

I really appreciate your help.

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 10 خرداد 1395 ساعت: 11:01

صفحه بندی