HTML5 filesystem - save file on disk - html

I wonder how I could save a file on disk in a specific folder. Currently, I use HTML5 filesystem API to save and store my information inside the browser. But I'd like to save them on disk and in the same directory as the file that I edit. And without the prompt window.
Thank you in advance for your help!

Chrome Apps can do this via the chrome.fileSystem API. There is a huge amount of information on the web about how to use that API, including extensive documentation from Google. A quick web search should get you what you need.
(Chrome Apps have a lot of APIs not available to ordinary web apps.)

This would be considered a security issue. HTML5 only allows filesystems to be accessed from a protected area on your local drive controlled by the browser.
However, there are ways of storing data to this specified area temporarily or permanently.
window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, yourFile);
window.webkitRequestFileSystem(window.PERSISTENT , 1024*1024, yourFile);

Related

Chrome Extension and IndexDB Integration

So, I am working on a project(building a chrome extension) that requires data to be stored on the local machine of the user. The size of data is quite large hence I thought of using IndexDB for this purpose.
My Question is whether is it possible to connect a chrome extension with IndexDB and query the database at the same time??
If Yes, Then how can I integrate them. In which file(popup.js or background.js or any other file) should I include the source code for creating the database.
I want the code for creating the database to run only once. After that I only want to update or delete data only.
If No, then is there any other way to achieve this?? The data is large hence I cannot store data in local storage.
Any paper, online material, advice or method from chrome developers or any other valid site would be helpful. Any example would help me alot.
Thankyou.
You can store tons of data in any HTML5 storage (including IndexedDB or localStorage) and chrome.storage.local with "unlimitedStorage" permission.
HTML5 data is stored per URL origin and each extension has its own one that looks like chrome-extension://id where id is a 32-character string that is the extension's id. In Firefox the origin looks like moz-extension://id.
Extension's own HTML5 storage:
can be accessed in any extension page (popup, options, background) just like you would do it in a web page, there are no differences.
cannot be accessed in a content script as it runs in a web page and thus can only access HTML5 storage of the web page's URL origin.
chrome.storage.local can be accessed in any extension page and in a content script.
No need for special event to create/upgrade your IndexedDB storage - it'll happen automatically if needed - simply open it as shown in the documentation whenever you need to access it and your onupgradeneeded callback will be invoked in case there was no DB or it was outdated.
Use a wrapper library for IndexedDB that provides a simplified syntax. Some are listed in the documentation, but you can probably find better ones yourself.

File name conversion for cloud storages?

Lets say I have a web URL to a file on a cloud storage (like Dropbox, Google Drive, etc). How do I convert that to the corresponding file path on my pc? On Android? On iOS?
Assuming of course I have the utilities/apps installed locally.
EDIT: I interested in file name the reverse direction too. (I.e. when I have the local file path, what is the web path?)
EDIT 2: #Greg just made me realize that the problem with file name is much worse on Google Drive than on Dropbox.
And that is very bad. :-(
The reason? Google has good search capabilities on Drive and therefor I and many, many others have put their documents on Drive. However, once I found it I must locate it on my on computer/device. (If I want to edit a pdf for example.)
EDIT 3: #Dan McGrath kindly asked what parts remain unsolved.
Short answer: All. ;-)
Long answer: My actual use case, see below.
My actual use case is a Zotero web app. Zotero is a reference database where you store references to scientific articles, web pages, etc. The items stored in Zotero may include PDF files or - which I prefer - links to PDF files.
I just want to be able to easy access (read) this PDF files from any computer through the web app. And on my own computer I want to be able to edit the files with my local PDF editor. (Be it Android, Windows or whatever.)
By using a cloud storage I do not have to download/upload the files myself. The cloud storage takes care of that part.
For the "reverse" scenario, that is, you have a file and you want the Dropbox shared link, you can use this API endpoint, assuming you're connected to the account via the API:
https://www.dropbox.com/developers/core/docs#shares

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.

Upload part of the file to Google drive

Is it possible to change a large file using google drive api, by uploading only changed part of the file, instead of entire file? I tried to find information about it in the API docs, but there's only support for continue uploading after connection reset. It seems to be an important feature.
No it's not possible. The Drive SDK treats files as atomic data blobs. It knows nothing about the format of content and hence what constitutes a change.

Is it possible to open an excel file in its current location not download it

I am writing a small web site for a company Intranet and have the following question that may be simple. Is it possible to open an Excel file from it's current location on the network instead of downloading it. So that any changes made are made to the actual file and not a downloaded version of it?
Thanks
Matt
Yes, it's possible, but then you would have to specify the address of the file in the local network, not as an HTTP address on the web server.
The user would naturally need to have access to the file on the network share, with write permission.
No. It is not possible to open a remote excel file across HTTP and write changes back to it.
Let's consider some other things you might be trying to do.
If you are running excel, all you can open are files visible to the file system APIs. That means files on your local disk and network file systems accessible via CIFS. Mapped drive letters, \\ pathnames, that sort of thing.
If you set up an Excel file for download from a web server, it will always be downloaded. Excel won't open it 'in place'.
The Microsoft technology solution that addresses what you seem to be asking for is Sharepoint.
Anything you open from a HTTP connection I believe is "downloaded" to the client. Its more how you "uploade" the changes.
But if thats what the customer wants I have some alternatives:
1) Use Dropbox or similar filesharing utils. Once someone saves a document in Dropbox, its automatically uploaded to the Dropbox account. The free version allows up to 2 GB of data. Thats quite a few Excel files.
2) Use Gmail/Google Apps. If you do you get 1 GB space for online documents. You can upload Office files suchs as Excel and they will be converted an online editable from within the Google Docs. You can share the files within the domain or even externally if you make that setting the admin part. Afterwards you can also download/export the Spreadsheet as Excel format. I havent tested how much of the standards you loose but ofcause its not a full Excel.
3) wait for Microsoft to finish their Office online. I bet that Excel version will do exactly what you are currently asking for by using some special plugin or MSIE9 technics. But I dont really know yet.
Hope some of this gave you some ideas?
If the file is in a network share on the same domain (or reachable from the domain your app is running from), it is possible, provided that
The share is readable and writeable by the domain\user the app runs under (via ownership or assigned role.)
The file is shareable (IIRC). This is important if multiple users (or apps) need to access it.
Other than that, a \domain\location path should be treatable just like a local (or disk mounted) path.
In your HTML document, create/place a link:
<a href='file:///H:/docs/foo/bar.xls'>Your Excel File</a>
Substitite your network UNC path for H:/docs/foo/bar.xls. Note the slashes instead of the regular UNC backslashes.