在未找到帆404中上载图像后,在angular2中加载图像时出错

时间:2017-11-08 02:34:55

标签: node.js angular

当我在风帆中加载图像时,我返回保存它的地址以显示它但我得到GET http://localhost:1337/images/user/cb8a85c7-3af6-49c1-a8cb-d42ae2fcab9d.jpg 404(未找到)但是图像在这些路径中正确加载

.TS

scan

AJAX

formData.append('image[]', inputEl.files.item(0));
  this.ajax.imageUp(formData).subscribe(dataImage=>{
    this.data.user.image = dataImage.json()['image'];
  });

userController.js

imageUp(data: any){
return this.http.post('user/imageup',data,{});}

in html

imageUp: function (req,res) {
req.file('image[]')
  .upload({
    maxBytes: 1000000, // Files limit(in bytes)
    dirname: path.resolve(sails.config.appPath, 'assets/images/user') // Path to copy the files
  }, function whenDone(err, uploadedFiles) {
    if (err) {
      // here must delete the created user before the error
      return res.serverError(err);
    }
    var image_real_name = 'images/user/'+path.basename(uploadedFiles[0].fd);
    res.json({image: image_real_name});
  });}

1 个答案:

答案 0 :(得分:0)

我认为你必须在服务器/ index.js中缺少这一行

app.use(express.static('assets'))

有关详细信息,请阅读:

https://expressjs.com/en/starter/static-files.html