Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:43:47+00:00 2026-06-15T15:43:47+00:00

I’m trying to understand HTML5 API. I’m designing the web application where the browser

  • 0

I’m trying to understand HTML5 API.
I’m designing the web application where the browser client need to download multiple files from server; user will perform something with the downloaded files and the application than need to save the state on user hard-rive. I understand that the browser can save these files only to its sandbox which is fine as long as the user can retrieve those files on the second time he starts the application.
Should I use BlobBuilder or FileSaver? I’m a bit lost here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:43:49+00:00Added an answer on June 15, 2026 at 3:43 pm

    I’m going to show you how to download files with the XMLHttpRequest Level 2 and save them with the FileSystem API or with the FileSaver interface.

    ##Downloading Files##

    To download a file you will use the XMLHttpRequest Level 2 (aka XHR2), which supports cross-origin requests, uploading progress events, and uploading/downloading of binary data. In the post "New Tricks in XMLHttpRequest2" there’s plenty of examples of use of XHR2.

    To download a file as a blob all you have do to is specify the responseType to "blob". You can also use the types "text", "arraybuffer" or "document". The function below downloads the file in the url and sends it to the success callback:

    function downloadFile(url, success) {
        var xhr = new XMLHttpRequest(); 
        xhr.open('GET', url, true); 
        xhr.responseType = "blob";
        xhr.onreadystatechange = function () { 
            if (xhr.readyState == 4) {
                if (success) success(xhr.response);
            }
        };
        xhr.send(null);
    }
    

    The success callback will receive as argument an instance of Blob that can be later modified and saved and/or uploaded to a server.

    ##Saving Files with the FileSystem API##

    As the Can i use… site points out there aren’t many browsers with support to the FileSystem API. For Firefox there’s an explanation for the lack of support. So, you will have to use Chrome to do this.

    First you will have to request a storage space, it can be either temporary or persistent. You will probably want to have a persistent storage, in this case you will have request a quota of storage space upfront (some facts):

    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    window.storageInfo = window.storageInfo || window.webkitStorageInfo;
    
    // Request access to the file system
    var fileSystem = null         // DOMFileSystem instance
        , fsType = PERSISTENT       // PERSISTENT vs. TEMPORARY storage 
        , fsSize = 10 * 1024 * 1024 // size (bytes) of needed space 
    ;
        
    window.storageInfo.requestQuota(fsType, fsSize, function(gb) {
        window.requestFileSystem(fsType, gb, function(fs) {
            fileSystem = fs;
        }, errorHandler);
    }, errorHandler);
    

    Now that you have access to the file system you can save and read files from it. The function below can save a blob in the specified path into the file system:

    function saveFile(data, path) {
        if (!fileSystem) return;
        
        fileSystem.root.getFile(path, {create: true}, function(fileEntry) {
            fileEntry.createWriter(function(writer) {
                writer.write(data);
            }, errorHandler);
        }, errorHandler);
    }
    

    And to read a file by its path:

    function readFile(path, success) {
        fileSystem.root.getFile(path, {}, function(fileEntry) {
            fileEntry.file(function(file) {
                var reader = new FileReader();
    
                reader.onloadend = function(e) {
                    if (success) success(this.result);
                };
    
                reader.readAsText(file);
            }, errorHandler);
        }, errorHandler);
    }
    

    In addition to the readAsText method, according to the FileReader API you can call readAsArrayBuffer and readAsDataURL.

    ##Using the FileSaver##

    The post "Saving Generated Files on Client-Side" explains very well the use of this API. Some browsers may need the FileSaver.js in order to have the saveAs interface.

    If you use it together with the downloadFile function, you could have something like this:

    downloadFile('image.png', function(blob) {
        saveAs(blob, "image.png");
    });
    

    Of course it would make more sense if the user could visualize the image, manipulate it and then save it in his drive.

    ###Error Handler###

    Just to fulfill the example:

    function errorHandler(e) {
        var msg = '';
    
        switch (e.code) {
            case FileError.QUOTA_EXCEEDED_ERR:
                msg = 'QUOTA_EXCEEDED_ERR';
                break;
            case FileError.NOT_FOUND_ERR:
                msg = 'NOT_FOUND_ERR';
                break;
            case FileError.SECURITY_ERR:
                msg = 'SECURITY_ERR';
                break;
            case FileError.INVALID_MODIFICATION_ERR:
                msg = 'INVALID_MODIFICATION_ERR';
                break;
            case FileError.INVALID_STATE_ERR:
                msg = 'INVALID_STATE_ERR';
                break;
            default:
                msg = 'Unknown Error';
                break;
        };
    
        console.log('Error: ' + msg);
    }
    

    ##Useful links##

    • Saving Generated Files on the Client-Side
    • Exploring the FileSystem APIs
    • New Tricks in XMLHttpRequest2
    • Reading Files in JavaScript Using the File APIs
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.