简体   繁体   中英

How can I save a large (8MB) file using JavaScript in Safari?

I'm looking for a way to save large files (exactly 8 megabytes) in Safari. I have tried using both the URI scheme along with the eligreyFileSaver and the flash plugin Downloadify. All of these cause Safari to allocate memory until the web worker process reaches about 2 gigabytes and then Safari crashes.

I realize there are questions like this one before, but I have tried everything those questions have resulted in. Links:

This code works on Firefox & Google Chrome (uses the eligreyFileSaver library for saveAs):

function io_saveData (){
    var bb;
    var buffer;
    var data;

    alert ("The file will now be saved.");

        bb = new BlobBuilder();
        for (var i = 0;i<kMapHeight;i++){
            var stduint8 = new Uint8Array (uint16map[i].buffer);
            var stduint8LittleEndian = new Uint8Array (kMapWidth*2);

            //byte swap work around
            for (var j = 0;j<stduint8.length;j+=2){
                stduint8LittleEndian [j] = stduint8 [j+1]
                stduint8LittleEndian [j+1] = stduint8 [j];

            }

            bb.append(stduint8LittleEndian.buffer);
        }

        var blob = bb.getBlob("example/binary");
        saveAs(blob, "Data File");

        bb = null;
        buffer = null;
        data = null;
}

I'm looking for a way for Safari to create a download without crashing. The deployment area is Mac OS X, so each machine will have apache built in along with PHP, I would rather not take that route though.

Here you go. First of store the file in HTML5 file system and after the completion data storing download it using filesaver api. I worked on it and I got good results with out blocking UI and crashes of browser. better to do it in webworkers to get performance of app.

Here are helpful article to it.

TEMPORARY storage has a default quota of 50% of available disk as a shared pool. (50GB => 25GB) (Not restricted to 1GB anymore)

http://updates.html5rocks.com/tag/filesystem

Unfortunately, Safari7 seems to not support writing files.

https://github.com/eligrey/FileSaver.js/issues/12

http://caniuse.com/#feat=filesystem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM