我使用文件传输插件以及文件选择器插件从设备获取所选文件的uri但我总是从服务器获得500错误,除了'文件' 你可以检查你是否转到api的url。
这是我的.ts文件构造函数和附加方法
export class ask {
fileTransfer: FileTransferObject = this.transfer.create();
constructor(public navCtrl: NavController, public http: Http, public navParams: NavParams, private transfer: FileTransfer, private file: File, public platform: Platform, private fileChooser: FileChooser) {}
public attach() {
let options: FileUploadOptions = {
fileKey: 'file',
fileName: 'name.jpg',
chunkedMode: false,
mimeType: "image/jpg",
params: {
"media_type": this.mediaType
}
}
this.fileChooser.open()
.then(uri => {
console.log(uri);
this.fileTransfer.upload(uri, 'http://darresny.com/file_transfer/', options)
.then((data) => {
// success
console.log('upload success =>', data);
}, (err) => {
// error
console.log('upload err =>', err);
})
})
.catch(e => console.log(e));
}
}