我一直试图将文件从移动设备上传到服务器(节点)。 我使用的技术是离子技术。我正在使用文件传输插件将文件上传到服务器,但这无法正常工作。
离子详细信息:
离子:
离子(离子CLI):4.1.2 离子框架:离子角3.5.3 @ ionic / app-scripts:2.1.4科尔多瓦:
cordova(Cordova CLI):8.1.2(cordova-lib@8.1.1) Cordova平台:Android 6.4.0 Cordova插件:没有列入白名单的插件(共15个插件)
系统:
NodeJS:v8.11.2(C:\ Program Files \ nodejs \ node.exe) npm:5.6.0 作业系统:Windows 10
客户代码:
public uploadVideo(path:any){
const fileTransfer: FileTransferObject = this.transfer.create();
let options1: FileUploadOptions = {
fileKey: 'video_upload_file',
fileName: path,
headers: {},
mimeType: 'webm',
params: {},
chunkedMode: false
};
fileTransfer.upload(path, 'https://forcast.co.in:2443/api/answer/fileuploadionic', options1)
.then((data) => {
const alert = this.alertCtrl.create({
title: 'Success',
subTitle: 'data saved successfully',
buttons: ['OK']
});
alert.present();
}, (err) => {
const alert = this.alertCtrl.create({
title: 'Error',
subTitle:JSON.stringify(err),
buttons: ['OK']
});
alert.present();
})
}
下面是服务器端代码。
const storage = multer.diskStorage({
destination: (req: Request, file, cb) => {
cb(null, video_path.dest + 'temp//');
}, filename: (req:Request, file, cb) => {
let fileName = req.params.id + '_' + req.params.qId + new Date().getTime() + '.' + req.params.mediaType;
cb(null, fileName);
}
})
const upload = multer({ storage: storage });
export class AnswerRoute extends BaseRoute {
constructor() {
super();
}
public static create():Router {
let router: express.Router = express.Router();
router.post("/fileuploadionic",(req: Request, res: Response, next: NextFunction) => {
new AnswerRoute().fileuploadionic(req, res, next);
});
return router
}
public fileuploadionic(req: Request, res: Response, next: NextFunction) {
this.logRequest(req);
console.log("in answerts for req files "+req.files)
}
}
在文件上载离子方法中,我只是打印要求。但是req.files说文件是未定义的错误。 我在哪里出错了?