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 5956383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:14:57+00:00 2026-05-22T18:14:57+00:00

I have a problem with BlobBuilder (Chrome11) I try to obtain an image from

  • 0

I have a problem with BlobBuilder (Chrome11)
I try to obtain an image from server with XHR request. Then i try to save it to local FS with BlobBuilder / FileWriter. Every example on the internet is about working with text/plain mime type and these examples work fine. But when i try to write binary data obtained with XHR, file size becomes about 1.5-2 times bigger than the original file size. And it cannot be viewed in Picasa / Eye Of Gnome.

var xhr = new XMLHttpRequest();
var photoOrigUrl = 'http://www.google.ru/images/nav_logo72.png';
xhr.open('GET', photoOrigUrl, true);
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && xhr.status == 200) {
        var contentType = xhr.getResponseHeader('Content-type');

        fsLink.root.getFile('nav_logo72.png', {'create': true}, function(fileEntry) {
            fileEntry.createWriter(function(fileWriter) {
                var BlobBuilderObj = new (window.BlobBuilder || window.WebKitBlobBuilder)();
                BlobBuilderObj.append(xhr.responseText);

                fileWriter.write(BlobBuilderObj.getBlob(contentType));
            }, function(resultError) {
                console.log('writing file to file system failed (   code ' + resultError.code + ')');
            });
        });
    }
}

xhr.send();

fsLink exists, this is extension.

  • 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-05-22T18:14:58+00:00Added an answer on May 22, 2026 at 6:14 pm

    The problem is that BlobBuilder.append(xhr.responseText) is detecting its argument as a UTF-8 string, which is what XHR returns, and not binary data, which is what it really is. There’s a couple of tricks to get the BlobBuilder reading it as binary data instead of string data:

    var xhr = new XMLHttpRequest();
    var photoOrigUrl = 'http://www.google.ru/images/nav_logo72.png';
    xhr.open('GET', photoOrigUrl, true);
    
    // CHANGE 1: This stops the browser from parsing the data as UTF-8:
    xhr.overrideMimeType('text/plain; charset=x-user-defined');
    
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var contentType = xhr.getResponseHeader('Content-type');
    
            fsLink.root.getFile('nav_logo72.png', {'create': true}, function(fileEntry) {
                fileEntry.createWriter(function(fileWriter) {
    
                    // CHANGE 2: convert string object into a binary object
                    var byteArray = new Uint8Array(xhr.response.length);
                    for (var i = 0; i < xhr.response.length; i++) {
                        byteArray[i] = xhr.response.charCodeAt(i) & 0xff;
                    }
    
                    var BlobBuilderObj = new (window.BlobBuilder || window.WebKitBlobBuilder)();
    
                    // CHANGE 3: Pass the BlobBuilder an ArrayBuffer instead of a string
                    BlobBuilderObj.append(byteArray.buffer);
    
                    // CHANGE 4: not sure if it's needed, but keep only the necessary
                    // part of the Internet Media Type string
                    fileWriter.write(BlobBuilderObj.getBlob(contentType.split(";")[0]));
                }, function(resultError) {
                    console.log('writing file to file system failed (   code ' + resultError.code + ')');
                });
            });
        }
    }
    
    xhr.send();
    

    This gave me a file with the same length as what xhr.getResponseHeader('Content-Length') suggests it should have been.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem when I try insert some data to Informix TEXT column via
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with Uploadify: I log in the project using: FormsAuthentication.SetAuthCookie(myName, false); Then,
I have problem when I try to set a background to .header - nothing
I have problem while sending messages from android to PC. Messages are send when
Have problem while getting data from Memcached on .NET MVC solution. I have this
I have problem calling a JavaScript function in an iframe from the parent page.
I have problem, when converting Windows application from .NET2.0 to .NET3.5. I do this
I have problem when creating a file in encoding 'utf-8' and reading it from
I have problem with sending a object from my webservice. I have created a

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.