Closed PabloPG closed 3 years ago
we also have similar issue, our codes are roughly like this, we are using Nativescript Vue
import { session } from "@nativescript/background-http";
const SESSION = session("image-upload");
class Something {
constructor()
{
this.counter = 1;
this.currentProgress = 0;
this.maxProgress = 0;
this.response = {};
}
post_bghttp(url, form_data) {
let request = {
url: GLOBAL.url() + url,
method: "POST",
headers: {
Authorization: "Bearer " + AUTH.getToken(),
// "Content-Type": "multipart/form-data"
"Content-Type": "application/octet-stream"
}
};
return await SESSION.multipartUpload(form_data, request);
}
bgHttpUpload(url, data) {
try {
let task = post_bghttp(url, data);
task.on("progress", this.progressHandler);
task.on("responded", this.respondedHandler);
task.on("error", this.errorHandler);
task.on("complete", this.completeHandler);
task.on("cancelled", this.cancelledHandler);
} catch (error) {
// error occured here
console.error(error);
}
}
progressHandler(e) {
this.currentProgress = e.currentBytes;
this.maxProgress = e.totalBytes;
if (this.counter === 1) {
this.ntcPrint(
"Total file size to be uploaded:",
e.totalBytes / 1000000 + " MB"
);
this.counter++;
} else {
this.ntcPrint(e.currentBytes / 1000000, "MB uploaded.");
}
}
errorHandler(e) {
console.error("error" + JSON.stringify(e));
}
respondedHandler(e) {
if (e.data.includes("success")) {
this.response = JSON.parse(e.data);
}
}
}
This is the data that we sent to the server for android phone
{
"name": "file_upload",
"filename": "/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-WA0003.jpg",
"mimeType": "image/jpg"
}
is there something wrong the filename that we are using?
More info:
Apparently it is sent 100%, but this error occurs after a while, but the image is on the server, only the return gave error.
Error is timeout, i can set a timeout config?
Resolved.
After changing the timeout I managed to solve the problem
Resolved.
After changing the timeout I managed to solve the problem
Hello there, may I know how do you change the timeout in nativescript?
Resolved. After changing the timeout I managed to solve the problem
Hello there, may I know how do you change the timeout in nativescript?
I changed only on android, adding:
method setRequestOptions on background-http.android.js (inside node_modules)
var timeout = options.timeout;
if (timeout) {
net.gotev.uploadservice.UploadService.HTTP_STACK = new net.gotev.uploadservice.http.impl.HurlStack(true, false, timeout, timeout);
}
and on index.d.ts
/**
* Use this to set the timeout connection in ms
*/
timeout?: number;
If the demo apps cannot help and there is no issue for your problem, tell us about it
Same times when i try to upload a image, i receive this error:
Which platform(s) does your issue occur on?
Please, provide the following version numbers that your issue occurs with: