react-native-background-upload
react-native-background-upload copied to clipboard
Can't complete upload due to 'timeout' and 'Error: Request aborted'
Hello everyone, I'm currently testing this library on Android 10 with different types of internet connections, including different distances between server and client and different upload speeds (GPRS, HSCSD).
const options = {
url: 'https://uploadserver.com/api/22/uploader.uploadPlain',
path: RNFS.DocumentDirectoryPath + '/' +upload.id+'-240.mpeg',
method: 'POST',
type: 'multipart',
field: 'upload',
customUploadId: upload.id,
maxRetries: 1,
headers: {
'Accept': 'application/json',
},
// Why do we put it here, it doesn't work anyway =(
notification: {
enabled: false,
autoclear: true
},
useUtf8Charset: true
}
When I use a poor internet connection it's unable to complete. The progress riches 57% and then it ends with a 'timeout' error.
My backend on a nodejs looks like this
const express = require('express');
const app = express();
app.use(multipart());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
On the server-side, I observe the following exception is rising right at the same moment:
Error: Request aborted
at IncomingMessage.onReqAborted (/node/node-upload/node_modules/multiparty/index.js:190:17)
at IncomingMessage.emit (events.js:315:20)
at abortIncoming (_http_server.js:532:9)
at socketOnClose (_http_server.js:525:3)
at TLSSocket.emit (events.js:327:22)
at net.js:674:12
at Socket.done (_tls_wrap.js:567:7)
at Object.onceWrapper (events.js:422:26)
at Socket.emit (events.js:315:20)
at TCP.<anonymous> (net.js:674:12)
Tried to use another backend, but unfortunately, the result is the same bad. Usually it riches 100% and then throw 'timeout' error
var http = require('http'),
path = require('path'),
os = require('os'),
fs = require('fs');
var Busboy = require('busboy');
http.createServer(function(req, res) {
if (req.method === 'POST') {
var busboy = new Busboy({ headers: req.headers });
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
var saveTo = path.join(os.tmpDir(), path.basename(fieldname));
file.pipe(fs.createWriteStream(saveTo));
});
busboy.on('finish', function() {
res.writeHead(200, { 'Connection': 'close' });
res.end("That's all folks!");
});
return req.pipe(busboy);
}
res.writeHead(404);
res.end();
}).listen(8000, function() {
console.log('Listening for requests');
});
I also can observe that the request is done successfully on the server-side, the received file has been stored and response headers have been sent.
Im having the same issue here
hello i found solution might help you in node node modules react-native-background-upload/android/src/main/java/.../RnUploader/UploaderMoudule increase connectTimeout var to whatever you want i did that and now timeout error is gone
Having the same issue, request fails with error 'timeout'. File is a bit larger. On my backend I get the correct logs and everything.