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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:44:44+00:00 2026-06-07T22:44:44+00:00

Im trying to achieve the same goal as OP there: Downloading mp3 files using

  • 0

Im trying to achieve the same goal as OP there:
Downloading mp3 files using html5 blobs in a chrome-extension
but not the him’s code, not the solution offered in discussion does not work for my google-chrome 19.0.1084.46.
Im working in chrome-console on the local (file://) page, and errors for this code:

finalUrl = "http://cs1076.userapi.com/u3040678/audio/d7ff6874cfa4.mp3";
var xhr = new XMLHttpRequest();

xhr.open("GET", finalURL, true);

xhr.setRequestHeader('Content-Type', 'octet-stream');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');

xhr.onreadystatechange = function() 
{
    if(xhr.readyState == 4 && xhr.status == 200) 
    {   
        var bb = new (window.BlobBuilder || window.WebKitBlobBuilder)();
        bb.append(xhr.responseText);
        var blob = bb.getBlob("application/octet-stream");

        var saveas = document.createElement("iframe");
        saveas.style.display = "none";

        saveas.src = window.webkitURL.createObjectURL(blob); 

        document.body.appendChild(saveas);

        delete xhr;
        delete blob;
        delete bb;
    }
}
xhr.send();

looks like

OPTIONS http://cs1076.userapi.com/u3040678/audio/d7ff6874cfa4.mp3 405 (Not Allowed) cs1076.userapi.com/u3040678/audio/d7ff6874cfa4.mp3:1
XMLHttpRequest cannot load http://cs1076.userapi.com/u3040678/audio/d7ff6874cfa4.mp3. Origin null is not allowed by Access-Control-Allow-Origin.

And the second subquestion:
in according to How can i generate a file and offer it for download in plain javascript? – is the creation of iframe the best way to offer file to download?

  • 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-07T22:44:45+00:00Added an answer on June 7, 2026 at 10:44 pm

    As Andrew stated your first problem is probably that your doing it from file://. Try doing it from an extension.
    After that you’ll probably like to know that from Chrome 19 you can ask for the response from an xhr to be a blob.
    Then for saving the file your better off using something like FileSaver.js to save the file. The iframe way works but you end up with an awful file name.
    Here’s an example to get you going….

    manifest.json

    {
      "name": "Download a file and click to save.",
      "version": "1.0",
      "permissions": [
        "tabs", "<all_urls>"
      ],
      "browser_action": {
          "default_title": "Download a file and click to save.",
          "default_icon": "icon.png",
          "default_popup": "popup.html"
      },
      "content_security_policy": "script-src 'self' https://raw.github.com/; object-src 'self'",
      "manifest_version" : 2
    }
    

    popup.html

    <!doctype html>
    <html>
      <head>
        <!-- https://github.com/eligrey/FileSaver.js -->
        <script src="https://raw.github.com/eligrey/FileSaver.js/master/FileSaver.min.js"></script>
        <!-- https://github.com/allmarkedup/jQuery-URL-Parser/tree/no-jquery -->
        <script src="https://raw.github.com/allmarkedup/jQuery-URL-Parser/no-jquery/purl.js"></script>
        <script src="popup.js"></script>
      </head>
      <body>
        <div id="message">Getting File.....</div>
      </body>
    </html>
    

    popup.js

    window.URL = window.URL || window.webkitURL;
    
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://or.cdn.sstatic.net/chat/so.mp3', true);
    xhr.filename = purl('http://or.cdn.sstatic.net/chat/so.mp3').attr('file');
    xhr.responseType = 'blob';
    
    xhr.onload = function(e) {
        var message = document.querySelector('#message');
        message.parentNode.removeChild(message);
    
        var link = document.createElement('A');
        link.innerText = 'Download File';
        link.href = '#';
        link.addEventListener('click', saveFile, false);
        document.body.appendChild(link);
    
    };
    
    xhr.onerror = function() {
        var message = document.querySelector('#message');
        message.innerText = 'Error getting file';
        this.filename = '';
    }
    
    xhr.send();
    
    saveFile = function() {
        saveAs(xhr.response, xhr.filename); // saveAs function is from FileSaver.js
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi there I am trying to achieve the same functionality of the Example Hover
I am trying to achieve the same as sudo chmod 755 myfile would. I
how can i paste something on multiple lines? i'm trying to achieve the same
this is the scenario i'm trying to achieve: a sound stored on the same
im trying to achieve something but i dont really know how I have set
I'm trying to achieve high frame-per-second on Windows GDI by using Windows Timer Queues.
Trying to achieve the goal of printing selected page's element ONE-TO-ONE - the exact
I am trying to achieve the same rotational effect like Maya in my project.
I am trying to achieve a scrolling effect using jQuery. I have a background
Essentially, I'm trying to achieve the affect of text-align:justify but with floating block elements.

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.