Parene Parene - 4 months ago 42
Javascript Question

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!!

Xan Xan
Answer

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.
Comments