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.