Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple file upload doesn't work in Safari 6.1 above, unless web inspector open

So I have a file upload site, which I develop using HTML5 chunking ability to upload multiple files. it works fine on Chrome, Firefox, IE (basicly browser with HTML5 capability) as well as Safari, but recently I test it out, Safari 6.0.5 works fine, but on Safari 6.1, If I upload multiple files, some files are 0 bytes. I'm not sure what happened.

When I tested, I upload about 70 files totalling 200MB, and each file is between 5-8MBish.. so there's no chunking happenening.. but when I check on the server, most file are 0 bytes (like it never get uploaded) except a few files (probably 3-5 files)

Is there any difference between Safari 6.0.5 and below, with Safari 6.1?

My code is basicly in a nutshell: Javascript will chunk each file if it's bigger than 10MB/file, if not it will just upload as is. then PHP will handle the upload (standard file upload style move_uploaded_file()).

function uploadFile(file_blob_chunk, file_name, file_part, total_file_chunk, file_id) {
    //create a progress bar based on file id (check if it's the 0 part, otherwise there will be multiple bar for same file)
    if(file_part == 0) {
        progressBar(file_id);
    }

    //ajax call for creating multipart data form
    fd = new FormData();    
    fd.append("file_for_upload", file_blob_chunk);
    fd.append("file_id", file_id);
    fd.append("file_name", file_name);
    fd.append("file_part", file_part);

    xhr = new XMLHttpRequest();
    xhr.fid = file_id;
    xhr.fid_name = file_name;
    xhr.fid_part = file_part;
    xhr.fid_total_chunk = total_file_chunk; 

    xhr.upload.fid = file_id;
    xhr.upload.fid_part = file_part;
    xhr.upload.fid_total_chunk = total_file_chunk;
    xhr.open("POST", "datas/upload/" + file_name + '/' + file_part, true);

    xhr.send(fd);

code wise it's something like that...

any idea what's wrong with safari 6.1?

I check the tmp folder, the tmp file during upload is 0 bytes..

NOTE: Safari 6.1+, If web inspector on, every file is uploaded correctly, if it's off, out of 10 files, only 3 got uploaded the rest is 0 bytes. what cause this difference?

like image 849
Harts Avatar asked Dec 11 '13 21:12

Harts


People also ask

How do I allow files to upload to my website?

If you want to allow a user to upload an external file to your website, you need to use a file upload box, also known as a file select box. This is also created using the <input> element but type attribute is set to file.

How do I limit multiple uploads in HTML?

Use two <input type=file> elements instead, without the multiple attribute. If the requirement is really just "have two different single inputs", then this is actually the best answer @Diego.


1 Answers

There are a lot of threads discussing the same problem:

file input size issue in safari for multiple file selection

https://github.com/moxiecode/plupload/issues/363

Any workarounds for the Safari HTML5 multiple file upload bug?

And the only workaround for this problem is to disable multiple upload for Safari.

like image 165
Oleg Avatar answered Oct 20 '22 00:10

Oleg