How to write a blob to a file in Chrome apps? - google-chrome

I am developing a chrome app which can download videos from server, save it locally and display it when user wants to. I am able to get the blob using xhr from server, but I do not know how to write it to a file, I am using Chrome.file system api. No luck. Any links to tutorials on using file write api ?

Take a look fileSystem API
Chrome Dev Editor uses it.

Related

Download files/videos from url and write them to disk without prompting save location dialoge using chrome app

I am writing a chrome app which needs to download videos from urls in background after specific time intervals.
Unlike chrome extension ( which has chrome.downloads api to deal with downloads ) chrome.downloads in not available for chrome apps.
If I use filesystem api, it shows the save location dialogue which I do not want. As, I need downloads to be dealt in the backgorund.
Is there any work around for this requirement ?

PhoneGap store HTML Files on Device

I have to build an App for Windows Mobile and iOS. So I decided to create this with PhoneGap.
The app should only display HTML-Files.
These files are stored on a server and can change every day.
So I created already an API which delivers the files.
My solution would be:
In my PhoneGap-App I use AJAX to get the files (this is no problem and should already work...).
To the question:
How can I store the files on the device? Is this possible with PhoneGap?
The app have to work offline too (because of this I need to store the files)...
And if this is possible: It should sync only the differences (between device/app and server) --> keyword rsync??
Thank you for your help!
Emanuel :)
Have you checked here?
You can definitely store files locally on android platform.(I have already done that). However, I haven't done it on IOS.
So please investigate, if features I gave the link above, available for safari (IOS).
Synching only diff should be implemented on the server side and should be responsibility of your API.
Yes you can store files locally.
I would recommend the Phonegap File Transfer plugin for downloading files. It supports iOS and Windows phone 7 and 8 and can download and save the file locally. At the Cordova file plugin github you can see the paths where you can save the files for iOS, I haven't found a table for windows phone yet.
But I would not recommend you download the HTML files since they can be very big. You should dynamically create the mobile pages you need, since you would only need to download the displayed text and attributes for some HTML-tags.
The way you can do this is by having a server back-end where you can change the content of the pages. The plain HTML should then be saved in a database with a creation and modification timestamp(needed to check if you have the latest updates). You would then pull the data out of the database with your PHP and echo it as a JSON. Your app just has to make a AJAX-GET request to the server and save the data locally in a database. I would recommend the Cordova SQLite Storage plugin for the local database. Whenever a page is opened you should dynamically create a mobile page.
This way your app doesn't request huge amount of data from a server, which can be more appealing to your app users.

Saving files on local machine by Chrome app

My chrome app needs to save a file with human-readable or standard format such as SQLite (It should be readable outside Chrome).
Is there any API suitable for this purpose?
Some files with .localstorage extension (SQLite format) are in Chrome\User Data\Default\Local Storage folder. Is it possible to create such files by the app?
Edited: The app should not ask user for extra permission.
Thanks for your consideration.
chrome.fileSystem API is what you need.
You will need to ask the user at least once where to save the file, but then you can retain the entry to write again to the same file/folder.
There is no way around asking the user to "escape the sandbox".
You'll want to use the Quota Management API. This is per-origin storage, and you request specific amounts of quota.
It sounds like you also want your users to open the files directly? There's an HTML5 filesystem explorer Chrome app that you can use. It'll show you the files, and you can figure things out from their URLs (e.g. I'm currently using filesystem:http://localhost:8000/temporary/bar for a local experiment).
Or are you looking for something more user friendly? I think you have to use file save in that case, the same way Google Drive does.

unable to persist indexedDB after reinstallation

I am unable to persist indexedDB when I re-install the chrome app which is using it. While I'm able to persist data using the sync file system across re-installations.
Should I use the storage API to push the indexedDB data in an array and store it in a file?
Is there a "C language" like way in JS(while making chrome app) to save data using structs and file access? Something like data structures using JS.
Am I going all wrong? And the solution to this problem is rather simple and obvious.
All what you get for app is the app sandbox and resources also using in the app sandbox. Chrome delete the sandbox and it resources after app was removed. And it's true behavior then you create a sandbox.
You need any back-end/server-side storage to store use data and sync it then user reinstall the app.

Is it possible for us to download a file to a sandboxed location using File API available in HTML 5?

I wanted to ensure the documents I let user download are programmatically manipulated throughout program.
I came to know that File API does give Apps the opportunity to manipulate them. But how can we store the Files in the sandboxed location?
You cannot directly read or write anything to the file system. You always have to go through either the usual upload/save dialog, or rely on desktop drag-and-drop (you can drag files into most modern browsers, and out of Google Chrome, at least).
It seems you can't let the browser download the file directly into File API's sandbox now. You have to fetch the file by yourself in JavaScript and write it to a file through File API. If the file is from the same origin, you can just fetch it by XHR.