2017-07-23 29 views
0

我在后台的知识是不是最好的...从高致病性禽流感的HTTP服务器的图像

我有我的包裹解决这个问题的头。

我有一个ng2上传图像,从那里它会做一个后需要的api,但我想有一个服务器(节点http-server)只是为了在那里添加文件,但我不知道如何从这里走:(

所以NG2(FE) - >哈皮(API) - > HTTP服务器(文件存储)

这些都是我的文件 upload.provider.js 常量FS = require('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); 
}, 

.... 

我不断收到这样的输出:

{ Error: ENOENT: no such file or directory, open ' http://192.168.33.1:8080/teaser-images/IX4A6789.jpg ' errno: -2, code: 'ENOENT', syscall: 'open', path: ' http://127.0.0.1:8080/teaser-images/IX4A6789.jpg ' }

会很感激的任何帮助,这一直缠着我。

我真的很想更好地理解流缓冲区的概念。

最佳, 乔

回答

0

我忘了浏览器的最重要的事实之一......它们是基于GET。

我试图将图像发送到它不是服务器的地方。在文件夹上创建一个HTTP服务器后:

new upload('../images', request, reply); 

再加入该文件夹,我能够访问我想要的图像上http-server

相关问题