react-native-background-upload icon indicating copy to clipboard operation
react-native-background-upload copied to clipboard

Can't complete upload due to 'timeout' and 'Error: Request aborted'

Open imhoze opened this issue 4 years ago • 4 comments

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)

imhoze avatar Oct 29 '20 10:10 imhoze

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.

imhoze avatar Oct 30 '20 10:10 imhoze

Im having the same issue here

lucasluca avatar Mar 01 '21 17:03 lucasluca

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

misag777 avatar Jul 10 '21 12:07 misag777

Having the same issue, request fails with error 'timeout'. File is a bit larger. On my backend I get the correct logs and everything.

MilanSingularity avatar Jun 12 '23 13:06 MilanSingularity