Parene
Parene

Reputation: 15

Chrome APP/Extension download file from URL

I've been researching and i did not found anything about that.

I need a chrome application that will run on Chrome OS be able to download a file (image, mp3, video, etc) and then display the content as HTML.

I mean if the app download a video, then play it on a video tag. The same for a image...download it and display on img tag.

Thanks!!

Upvotes: 1

Views: 1631

Answers (2)

Gleb Dolzikov
Gleb Dolzikov

Reputation: 834

I also worked with this issue, here a working example of saving to filesystem + showing on screen:

var video = document.getElementById("video");

fetch('http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_20mb.mp4')
  .then(function(response) {
    return response.blob();
  })
  .then(function(myBlob) {
    var objectURL = URL.createObjectURL(myBlob);
    video.src = objectURL;

    var config = {type: 'saveFile', suggestedName: chosenEntry.name};
    chrome.fileSystem.chooseEntry(config, function(writableEntry) {
      writeFileEntry(writableEntry, myBlob, function(e) {
        output.textContent = 'Write complete :)';
      });
    });
  })

Upvotes: 1

Xan
Xan

Reputation: 77523

See Chrome App documentation on Handling external content. It provides a good overview.

A short version:

  1. Declare the origins you're going to access in the manifest.
  2. Fetch the resource via XHR (or, indeed, Fetch API).
  3. Use the response as a blob: (you can plug it into a <video src="...">, for instance).
  4. Optionally, save the resource locally.

Upvotes: 0

Related Questions