jbarbin / EPub-Reader

An open web app for reading epub e-Books
9 stars 5 forks source link

Opening files on FirefoxOS #13

Open Yoric opened 11 years ago

Yoric commented 11 years ago

Unfortunately, <input type="file"> doesn't work yet on FirefoxOS. You will need a non-trivial workaround to be able to open files on FirefoxOS.

Detect whether <input type="file"> is supported

Something along the lines of

var myInput = document.getElementById("myInput");
if (myInput.type != "file") {
   // Not supported, use fallback
}

If it is not supported, call a web activity

Web Activities are a mechanism to let one application request data from another application. If <input type="file"> is not supported, the best way to request a file is to launch Web Activity pick with type “application/epub+zip”. This will let any application that can pick such files handle the task of opening the file.

Implement your own web activity for opening a book

... unfortunately, for the moment, there are no such applications, so you will have to implement one using Device Storage to access the file. You should probably use device storage "pictures", for the lack of a better device storage.

aratagobal commented 11 years ago

Thank you for opening this issue. Do you have any documentation or example about how to implement a Device Storage to access a file? My internet searches are unsuccessful...

jdm commented 11 years ago

https://github.com/jdm/bookworm/blob/master/bookworm.js#L2

aratagobal commented 11 years ago

Thank you it helps!

aratagobal commented 11 years ago

Do you know it's possible to test a Device Storage without a phone?

Yoric commented 11 years ago

I haven't tested it myself, but the code to do so exists in Desktop and Android Firefox.

jdm commented 11 years ago

I was not able to use device storage in desktop Firefox (no idea about mobile). I had to use the Firefox OS simulator to test it: http://people.mozilla.org/~myk/r2d2b2g/

aratagobal commented 11 years ago

This is what i did to, but how can i add some files into "pictures" or musics"? There are actually no files in there.

jdm commented 11 years ago

I'm pretty sure they map to your ~/Picture and ~/Music directories on OS X and Linux, and c:\Users[username]\Pictures and c:\Users[username]\Music on Windows.

aratagobal commented 11 years ago

Great! Thank you!

Yoric commented 11 years ago

All the details are here, if you feel inclined to search the C++ source code of Firefox/FirefoxOS.

aratagobal commented 11 years ago

I'm having some difficulties to implement DeviceStorage. I use the storage "music" and "pictures" but those storages only specific format. Jpg. Png for "pictures". Mp3 for "music"). Storage device does not recognize .epub files

I'm trying to view files using this code:

var storage = navigator.getDeviceStorage ("pictures");

if (storage) {

var = booksCursor storage.enumerate ("books");
var i = 0;

booksCursor.onsuccess = function (e) {
var book = booksCursor.result;
console.log ('cursor' + i);
console.log (book);
console.log (book.name);
DisplayIndex (book);
i + +;
booksCursor.continue ();
};
booksCursor.onerror = function (e) {
alert (booksCursor.error.name);
};
}

function DisplayIndex (book) {
   var list = document.getElementById ('books');
     var li = document.createElement ("li");
     li.textContent = book.name;
     list.appendChild (li);
}

This displays to me all files except .epub in the directory "books".

Yoric commented 11 years ago

That doesn't sound good. You should ask on irc.mozilla.org, #openwebapps.

On 3/18/13 2:38 PM, Tony wrote:

I'm having some difficulties to implement DeviceStorage. I use the storage "music" and "pictures" but those storages only take into account the specific files to storage (. Jpg. Png for "pictures". Mp3 for "music"). Storage device does not recognize the files. Epub.

I'm trying to view files using this code:

var storage = navigator.getDeviceStorage ("pictures");

if (storage) {

var = booksCursor storage.enumerate ("books"); var i = 0;

booksCursor.onsuccess = function (e) { var book = booksCursor.result; console.log ('cursor' + i); console.log (book); console.log (book.name); DisplayIndex (book); i + +; booksCursor.continue (); }; booksCursor.onerror = function (e) { alert (booksCursor.error.name); }; }

function DisplayIndex (book) { var list = document.getElementById ('books'); var li = document.createElement ("li"); li.textContent = book.name; list.appendChild (li); }

This displays to me all files except .epub in the directory "books".

— Reply to this email directly or view it on GitHub https://github.com/jbarbin/EPub-Reader/issues/13#issuecomment-15054963.

Yoric commented 11 years ago

Good news: you should not need this anymore. FirefoxOS should be able to handle <input type="file"> within a few days.

aratagobal commented 11 years ago

Yes!! That's a really good news!

Yoric commented 11 years ago

Good news: <input type="file"> now works. Bad news: it won't let me pick your books just yet. You (or someone else) still need to write a small application to open ebooks :/