Я не могу загрузить изображение на внешний сервер из моего приложения. Когда я пытаюсь сделать это, VSCode возвращает: ОШИБКА Ошибка: невозможно преобразовать объект в 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);
}