【发布时间】:2015-01-01 01:43:43
【问题描述】:
我正在使用 (MySQL)EAN 堆栈开发 Web 应用程序。我在 MySQL 中将 png/jpg/pdf 保存为 BLOB。现在,我可以在 Node.js 中使用 Sequelize.js 将它们检索为 Buffer 对象:
exports.loadUploadedFiles = function(req, res) {
db.File.findAll().success(function(files) {
//res.send(files[0].dataValues.data.toString('ascii')); // I have tried to convert a Buffer to ascii and sent it to Angular.js, however, I still don't know how to transform them to a file link.
res.send(files); // How can I return the Buffer objects to Angular.js
}).error(function(err) {
console.log(err);
res.sendStatus(500);
});
};
我尝试了两种方法:
将 Buffer 对象返回给 Angular.js,然后找到一种方法从它们生成可下载的链接。
使用 bufferObject.toString('ascii') 将 Buffer 对象转换为 ascii,然后找到将这些 ascii 转换为可下载链接的方法
我已经尝试了一天,但在这两种方法中仍然无法弄清楚:(,任何建议都将不胜感激!
【问题讨论】:
标签: javascript mysql angularjs node.js