我正在开发一个关于声音文件的移动应用程序(如.3gp,.wav),我希望将用户的记录发送到.net web api服务器。对于这种情况,我使用了Ionic Native FileTransfer插件。
console.log(this.postModel.sound.substr(this.postModel.sound.lastIndexOf('/') + 1));
let fileTransfer: FileTransferObject = this.transfer.create();
let options: FileUploadOptions = {
fileKey: 'file',
fileName: this.postModel.sound.substr(this.postModel.sound.lastIndexOf('/') + 1),
mimeType: 'audio/3gp',
httpMethod: 'post',
chunkedMode: false,
headers: {
"Authorization": btoa("user" + ":" + "password"),
'Content-Type': 'multipart/form-data',
}
}
var params = {};
params['userID'] = this.postModel.userID;
params['dateTime'] = this.postModel.dateTime;
options.params = params; //this.postModel.sound is path of files
fileTransfer.upload(this.postModel.sound, this.apiUrl + '/posts/record', options, true)
.then((data) => {
console.log('Posted!')
}, (err) => {
console.log('ERROR!' + err.value)
});
所以,这个函数的请求可以通过web api
捕获[System.Web.Http.HttpPost]
[System.Web.Http.Route("record")]
public IHttpActionResult PostRecord(){
var httpRequest = HttpContext.Current.Request;
....
}
但是,我在Current.Request中看不到Ionic的请求。
如何解决?