【发布时间】:2018-03-27 13:05:37
【问题描述】:
我正在尝试从使用 NativeScript 制作的移动应用发布到我在 C# 上制作的 webapi。
我同时使用nativescript-imagepicker 和nativescript-background-http。
但是error 事件总是在触发。
这是我的代码: 我的两个进口:
import * as imagepicker from "nativescript-imagepicker";
import * as bghttp from "nativescript-background-http";
这就是我获得图像 uri 的方式:
SelectImage(): void {
let context = imagepicker.create({
mode: "single"
});
context.authorize()
.then(() => { return context.present() })
.then((selection) => {
selection.forEach((selected) => {
this.signupModel.CIPath = selected.fileUri;
})
}).catch((e) => {
console.log(e);
});
}
这就是我尝试发布数据的方式:
SignUp(): void {
let session = bghttp.session("image-upload");
let request = {
url: "http://localhost:53286/api/Home/Signup",
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": this.signupModel.CIPath
},
description: "{ 'uploading': 'Uploading file...' }"
};
let task: bghttp.Task;
let params = [{
name: "ImageCI", mimeType: "image/jpeg", filename: this.signupModel.CIPath
}, {
name: "Rut", value: this.signupModel.Rut
}, {
name: "Name", value: this.signupModel.Name
}, {
name: "Address", value: this.signupModel.Address
}, {
name: "Commune", value: this.signupModel.Commune
}, {
name: "PhoneNumber", value: this.signupModel.PhoneNumber
}, {
name: "Email", value: this.signupModel.Email
}, {
name: "Password", value: this.signupModel.Password
}];
task = session.multipartUpload(params, request);
task.on("error", (response: any) => {
console.log(JSON.stringify(response));
alert({title: "Sistema 3 Esferas", message:"Error subiendo imagen...", okButtonText: "Cerrar"});
});
task.on("responded", (response: any) => {
console.log(JSON.stringify(response));
});
}
我做错了什么?提前致谢。 :)
【问题讨论】:
-
在模拟器上测试?如果是这样,请记住默认配置不适用于
localhost- 有关详细信息,请参阅此线程stackoverflow.com/a/39958955/4936697 -
错误响应是什么?
标签: asp.net-web-api2 nativescript multipartform-data