Modify app assets using Phonegap's File API - javascript

I worked on a phonegap application using html5 for a month. I handle offline JSON files using File API.
It seems that the JSON files I store are automatically saved on /mnt/sdcard/.
The problem is, I find myself handling 3 files for each file I want.
1 st the file packaged with my app (js/products.js)
2 nd the remote file that sends me updates (http://website/remote_products.js)
3 rd the local file on sdcard I update with the remote data. (/mnt/sdcard/updated-products.js)
Is it possible to - instead of saving on the sdcard - update my app's assets using File API ?
Or create a new file in my app assets folder ?
(the JSON file packaged with my app. Found in js/products.js)
If yes, how plz ?
thx

Sadly, you cannot modify the files in /android_assets/www with the File API.
See this answer to a slightly different question answered by one of the PhoneGap Android devs: https://stackoverflow.com/a/8966227/878602
"You can't do what you want to do. The files in the assets directory are not technically on the file system so they are not accessible via the File API. This means calling window. resolveLocalFileSystemURI() will not return you a FileEntry."

You might consider to utilize Mott:
https://github.com/imlucas/mott, e.g. http://phonegap.com/blog/2013/04/23/story-behind-exfm/
It seems to be able dynamically version, update and persist update of any local asset.

Related

Creating a web UI for an ftp file server that can archive folders as ZIP to download

I'm trying to create a file server to serve a bunch of files for download and have a web-based UI to search/filter and download the files.
Right now i'm using a basic FTP server and i'm planning to create a simple (flask+js) web app that will redirect me to the ftp url for the selected file so it can be downloaded. The web app is needed so I can create my own tagging and filtering system.
However, i'm having trouble finding out how to download whole directories and folders as a zip. Basically like how google drive can have a "Download as zip" function while still keeping the raw folder available for browsing.
Is there a way to do this?
This involves working with "blobs", a JavaScript way of dealing with streamable binary data.
I haven't tried this particular library myself, but there's an article here about using the JSZip library specifically for the kind of thing I think you're talking about: https://davidwalsh.name/javascript-zip

Is there a way to get a full filepath from an input in Html?

I'm developping a web application with ASP Core 3.0 that will be used with Google Chrome.
The user of this app need to be able to specify the location of a file.
I don't need to upload the file I just need the full path of its location. The file can be in different folders on my company network (this folder is accessible by all future users of the app and by the server hosting it).
Is there a way to get this information ? I know that it's not possible to get it via the html5 input type="file" on chrome.
Since my server has access to this repository, I was thinking of doing ajax call to build the path of this file (basically building a light version of an html5 input file) but I was wondering if there were an easier way...
Any idea ?

How to view local files in web browser by displaying and creating a link to local files stored in your computer in your webApp?

I have created a webapp using JSP,Html and Javascript which currently runs on my localhost using apache webserver. I want to display the files and folders and of a directory in local computer. I also want to create a download link or view link of those so that when anyone click on it it will be viewed in new tab or become downloadable as it happens in any ftp server. I know similar type of question has
been asked but none of them worked for me.
To create the download link I used
Download
this does not work as it is not in my webapp path and download attribute also does not work in internet explorer.
I'm not sure why you are exposing your local drive contents on the web but here's an option:
On the page that should display the files, in java code, list all
folders and files then for each file/folder show a link to some page
(for example "navigateLocalDrive" that sends the path of the clicked
file/folder like this:
Download
Now in that jsp, check if the GET variable is a path for a file or a directory,
if its a file, just send it back in the response, if its a
directory, list all files/folders and do the same as in step 1
Please note:
How I encoded the file path in the href in order to work properly.
The Access permissions for the webserver should allow write/read to that path (I'm already doing it on my Tomcat server on local host with the default setup no change needed)
For your reference, here are some helpers for this task:
How to list contents of a server directory using JSP?
Downloading file from JSP/Java
I am not sure if this is possible. In general the access rights are limited to the src and webContent Folder (for your html coding mentioned above for sure) . This is also reasonable, because you do not want to access or change data on your Computer in general, because after local development you want to deploy your web application to a server.
To make a test copy some file to the webContent and you will be able to download it. Within your Java coding you can use some IO package like java.io.File to navigate over folders and files. However keep in mind, that you will get some exceptions like
java.io.FileNotFoundException: C:\WeatherExports\export.txt (Access is denied)
if you want to access files outside the server.

Load html in windows strore app from appdata folder

I'm developing windows store app using javascript, html5 and C#. I have developed functionality which downloads zip from web and extracts it to "AppData" folder in "C" drive. That zip file has HTML files. So my question is, I want to display that html in windows app. I'm able to load html from web in iframe but not from local drive. I also tried to do it by giving absolute path in iframe but not working.
Basically, StoreApp's WebView can load the local resource from your app's local storage. "app's local storage" means.. Windows.Storage.Current.ApplicationData.Current.LocalFolder, etc.
If the resources are located outside of your app's local storage, you have 2 options:
Copy the all resources to your local storage.
Create a 'stream' that have all required resources, then give the stream to webview.
1 is easy.
To refer your html resource, use following syntax.
ApplicationData.Current.LocalFolder - "ms-appdata:///local/hogehoge.html"
ApplicationData.Current.TemporaryFolder - "ms-appdata:///temp/foobar.html"
App packages file (like Asset) - "ms-appx-web:///Assets/boee.html"
2 is complicated. Below is an example for 2.
XAML WebView control sample
Use webbrowser.NavigateToString("parameter"). Your question is a possible duplicate: Local HTML File - WebBrowser - Windows phone 7

How to locate all images in a directory using jQuery

I'm developing an application which runs on a localhost server.! In this application I do ajax calls and get items from a local h2 DB! Using the response I create dynamic elements using jQuery. The elements use an item image as background and the requirement is that I should get the images from a local folder. ( The folder is created when the server is first started and the images are synchronized from a main server over the intranet. ) The folder hierarchy is shown below.
c:/----
|
zharaimages/ -----
|
[item id]/-----
|
[image].jpg
The image can contain any name for it but will be a jpg. How can I read the file system using jQuery to get the necessary image file when the item is dynamically loaded. I thought of this method but for that I can only read a file with a static name. I want to write a method where the image name can be anything.
clone.css('background-image','c:/zharaimages/' + items[i].itemId + '/image.jpg');
Any ideas or plugins are welcome.
Thank you.
update
This is a deployable application which uses an embedded jetty server. The folders are in the same computer as the application is!
Unfortunately a big NOOOOOO...
javaScripts cannot read or write files on users' computers (File API - not currently supported by many browsers - allows files to be read by scripts if the user specifically chooses to allow it),
though they can cause the browser to load remote pages and resources like scripts or images, which the browser may choose to cache locally.
They cannot create files on the server (except by communicating with a server side script that creates files for them).
You have to make a server request(many ways...) for the resources.
I'm not sure weather its possible with HTML5 or not
jQuery runs on the browser.
The files are on the server.
The only way that jQuery can read the files on the server is if it makes an AJAX call to the server, and your web server enumerates them.

Categories

Resources