首页 > 解决方案 > 无法使用 ng2-file-upload 将带有表单数据的文件从 angular 上传到sails.js

问题描述

我的 app.component.html 包含

<input type="file" ng2FileSelect [uploader]="uploader" #photoupload="ngModel" required id="photoupload" name="photo_upload" [(ngModel)]="personal.photo">

app.component.ts 包含

this.uploader = new FileUploader({ url: "http://localhost:1337/api/fmng/create" });
this.uploader.onBeforeUploadItem = (item) => {
    var formData = [{ "formdata" : this.personal }];
    item.formData.push({ fileData: formData });

};

我的风帆应用程序控制器中的代码是

req.file('photo_upload').upload({ dirname: require('path').resolve(sails.config.appPath, 'assets/images') }, function (err, uploadedFiles) {
     if (err) return res.serverError(err);
     console.log('req all params ' + req.allParams());
}

为什么我的 Angular 应用程序没有对 URL 发出请求?

标签: angularsails.jsng2-file-upload

解决方案


推荐阅读