File upload failing for files with larger size

I have an option to upload files where I am trying to upload a firmware image of size 20MB but the ajax call fails after being stalled for 2 min while the same approach works for files will lesser size.

Attaching my code below:
HTML file:

<form>
   <input type="file" id="file_name" name="file_name">
   <input type="button" value="Upload" onclick="uploadFile()">
</form>

On click method:

<script>
    function uploadFile() {
        var url = '<%=url("admin/system/file_transfer/upload_file")%>';
        var data = new FormData();
        var request = new XMLHttpRequest();

        // File selected by the user
        data.append('file_name', document.querySelector('#file_name').files[0]);

        // Increase timeout to 5min
        request.timeout = 300000;

        request.open('post', url);
        request.send(data);
    }
</script>

Lua controller:

function uploadFileTransfer()
    local file_name = luci.http.formvalue('file_name')
    if file_name then
        tmpfile = "/tmp/" .. file_name[1]
        luci.util.perror(tmpfile)
        local file
        luci.http.setfilehandler(
            function(meta, chunk, eof)
                if not nixio.fs.access(tmpfile) and not file and chunk and #chunk > 0 then
                    file = io.open(tmpfile, "w")
                end
                if file and chunk then
                    file:write(chunk)
                end
                if file and eof then
                    file:close()
                end
            end
        )
     end
end

Tried increasing request.timeout to 5 min in ajax call but still the request failed after 2 min
Please let me what changes should be done for uploading larger files.

One question is how much RAM does your device have?

2 Likes

1GB RAM. Not sure whether RAM should be any issue. SCP works perfectly fine.

Any solution for this. Having a similar issue where in the large file upload gets interrupted with an error after the duration of script timeout in the uhttpd config file.

File upload call does not complete the transfer within the stipulated time of the script timeout mentioned in uhttpd config file which is resulting in the connection reset error.

What are the available options to upload the file successfully without increasing the script timeout?

Could not find anything on the forum. Has no one had this problem during upload of large size files over Luci with slow network?