我在后台的知识不是最好的..。
我有问题把头绕在这上面。
我有一个ng2上传映像,从那里它将对api做一个post req,但是我希望有一个服务器(http-server from节点)来添加那里的文件,但是我不知道如何从这里:(
因此ng2 (FE) -> Hapi (API) -> http-server (文件存储)
这些是我的文件upload.provider.js const =upload.provider.js(‘fs’);
class UploadProvider {
constructor(path, request, reply) {
this.path = path;
this.data = request.payload;
this.reply = reply;
this.image();
}
image() {
if (this.data.uploadFile.hapi.filename) {
const name = this.data.uploadFile.hapi.filename.replace(/\ /g,'-');
const path = this.path + name;
const file = fs.createWriteStream(path);
file.on('error', (err) => {
console.error(err)
});
this.data.uploadFile.pipe(file);
this.data.uploadFile.on('end', (err) => {
var ret = {
filename: this.data.uploadFile.hapi.filename.replace(/\ /g,'-'),
headers: this.data.uploadFile.hapi.headers
}
this.reply(JSON.stringify(ret));
})
}
}
}
module.exports = UploadProvider;teaser.controller.js
const upload = require('../providers/upload.provider');
const Teaser = require('../model/teaser.model');
var teaser = {
upload: (request, reply) => {
new upload('http://127.0.0.1:8080/teaser-images/', request, reply);
},
....我一直得到这个输出:
{错误: ENOENT:没有这样的文件或目录,打开'http://192.168.33.1:8080/teaser-images/IX4A6789.jpg‘errno:-2,代码:'ENOENT',syscall:' open ',path:'http://127.0.0.1:8080/teaser-images/IX4A6789.jpg’}
我真的很感激你的帮助,这一直困扰着我。
我真的很想更好地理解关于流缓冲区的概念。
最好,乔
发布于 2017-08-04 17:53:47
我忘了浏览器最重要的事实之一..。它们是基于GET的。
我试图把图像发送到一个不是服务器的地方。在文件夹上创建http-服务器之后:
new upload('../images', request, reply);然后在我能够访问我想要的图像的文件夹上添加一个http-server。
https://stackoverflow.com/questions/45267437
复制相似问题