user3345456
user3345456

Reputation: 41

How to load local resource in Chrome App

In my Chrome App,I want to load local resources such as audio from user's disk. If I add the absolute path in my code, the Chrome says "not allowed to load local resource"... So,how to achive it? Thx Please this is app not extension.

Upvotes: 1

Views: 8070

Answers (1)

mgiuca
mgiuca

Reputation: 21357

Chrome Apps are not allowed to access the user's file system directly. file:// URLs are forbidden, as are all the other ways you might try for accessing a file like /home/user/music/demo.mp3. This is by design (so users can install a random Chrome App and trust that it isn't going to read or write their files).

However, Chrome Apps have several APIs available for accessing sandboxed file systems. Since your example is an MP3 file in /home/user/music, you probably should use chrome.mediaGalleries, which will prompt the user for access to common media directories (like /home/user/music) at install time. Then you will be able to access certain file types in certain directories, and prompt the user for music and images in other directories.

As sowbug suggested, you could also use chrome.fileSystem, where you can prompt the user to open a file or directory of their choosing. This will give you access to all files in those directories, but you should only use this if you want non-media file types.

Upvotes: 2

Related Questions