I can't upload an image to external server from my app. When I try do this, VSCode return: ERROR Error: Cannot convert object to Ljava/lang/String; at index 0 . I use nativescript-background-http plugin in my app. My code:
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);
}