我无法从我的应用程序将图像上传到外部服务器。当我尝试执行此操作时,VSCode返回: ERROR错误:无法将对象转换为Ljava / lang / String;位于索引0 处。我在我的应用程序中使用nativescript-background-http插件。我的代码:
private file: string;
private url: string;
private counter: number = 0;
private session: any;
public events: { eventTitle: string, eventData: any }[] = [];
constructor(private gallery: GalleryService, private params: ModalDialogParams) {
this.image = params.context;
var pict = new Image();
pict.src = this.image;
console.log(pict.src);
this.file = pict.src;
this.url = "http://127.0.0.1:80";
this.session = bgHttp.session("image-upload");
}
uploadPhoto() {
const name = this.file;
const description = "Upload";
const request = {
url: this.url,
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": name
},
description: description,
androidAutoDeleteAfterUpload: false,
androidNotificationTitle: 'NS HTTP back',
};
let task: bgHttp.Task;
task = this.session.uploadFile(this.file, request);
}