why am I getting "Possible Unhandled Promise Rejection" error when using expo-file-system to download videos

225 Views Asked by At

I am trying to download a video using expo-file-system. It used to work sometimes, but sometimes gave me this error. Now I changed some stuff (I don't remember exactly what) and now I'm getting the error constantly.

const result = await FileSystem.createDownloadResumable(
    `http://192.168.0.12:5000${data.staticPath}`,
    vidDir + data.path,
    {},
    (downloadProgress) => {
        console.log(downloadProgress);
    }
).downloadAsync().catch(function(error) {
    console.log("Error: " + error.message);
    throw error;
});

The downloadProgress shows that the download is nearly done but then the error happens and the download stops

 LOG  {"totalBytesExpectedToWrite": 5632573, "totalBytesWritten": 5089880}
 LOG  Error: unexpected end of stream
 WARN  Possible Unhandled Promise Rejection (id: 2):
Error: unexpected end of stream
construct@[native code]
construct@[native code]
_construct@http://192.168.0.12:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:19240:28
Wrapper@http://192.168.0.12:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:19202:25
construct@[native code]
_createSuperInternal@http://192.168.0.12:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:94967:322
CodedError@http://192.168.0.12:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:94975:26

This is the server code, made with Flask, and it just returns the static path of the file to be downloaded

@app.route("/requestVideo/<url>")
def requestVideo(url):
    path = vid_request.download(url, "static")
    
    info = {
         "path": path,
         "staticPath": url_for('static', filename=path)
    }

    return jsonify(info)

How can I fix it so the download finishes?

0

There are 0 best solutions below