JavaScript: Read big files in chunks - WebkitBlobResource error 1 on iOS Safari

I’m trying to read a rather big file in chunks using FileReader (File selected from a field). Works fine on Android, Chrome, Firefox etc., but somehow on iOS Safari the FileReader stops reading the chunks exactly after 60 seconds. The error I am seeing is WebkitBlobResource error 1. Makes me wonder if this is some kind of permission error or somehow iOS Safari revokes the File blob.

Sample code:

let file = <input type="file">

let chunkSizeToUse = (1024 * 1024) // 1 MB chunks
let offset = (0 - chunkSizeToUse)

let readInterval = setInterval(() => {
    if(offset < file.size){
        offset += chunkSizeToUse

        let fileReader = new FileReader()

        fileReader.onload = () => {
            let arrayBuffer = fileReader.result

            //further chunk processing
        }

        fileReader.onerror = (err) => {
            console.log(err) // WebkitBlobResource error 1 exactly after 60 seconds of processing
        }

        fileReader.readAsArrayBuffer(file.slice(offset, (offset + chunkSizeToUse)))
    }
    else{
        clearInterval(readInterval)
    }
}, 100)

For easier and direct debugging on an iOS device using Safari I'm gonna link this JSFiddle:

https://jsfiddle.net/L17uymvp

Just select a file and wait for the counter do go to zero.

All of this makes it impossible for some users to upload large files. Our webapp processes each chunk individually (encryption), so we have to work with chunks.

If that occurs always at 60 seconds, not at the same file position (if you can check), that looks more like a time out. Did you try with a smaller file that would need just less than 60 s ?

I've checked multiple files, increasing the chunk size etc. but it always happens at 60 seconds. Unfortunately only leaving it and allowing small files is not an option, as this works on all other browsers except for mobile safari.

So that looks like a timeout issue. Don't know if you can set the timeout value. Maybe this will provide some hint ? https://stackoverflow.com/questions/31140212/failed-to-load-resource-request-timed-out-on-safari

Looks like this is indeed a bug with the webkit engine on iOS, bug filed: https://bugs.webkit.org/show_bug.cgi?id=228683

This can be closed.

JavaScript: Read big files in chunks - WebkitBlobResource error 1 on iOS Safari
 
 
Q