Access downloaded pdf file path in HTML5 file system and display it in webview - google-chrome-app

In my chrome app, I am using HTML5 file system to save the pdf files to sand box.Downloading is working fine.But how do i access that downloaded file path? I want to give that path as webview source.

The best way, if it works, would be to use a filesystem URL. To get this use FileEntry.toURL
These don't work on external files (i.e. files that come from chrome.fileSystem.chooseEntry and are outside the app's sandbox) but should work for files in the app's sandbox.
Note, I am referring to filesystem:// urls not file://urls, which won't work as Marc Rochkind has pointed out in his answer.
Disclaimer: I haven't tested this, but I believe it should work.

You need to get the contents of the PDF into a data URL. See my answer to this question:
Download external pdf files to chrome packaged app's file system

Related

Load PDFs from local file share

I'm developing a web app for in-house use and I'm looking for a better way to display PDFs.
I've played around with Adobe's 'Work with Local File' example from GitHub, Adobe GitHub Example, and it works great using the file picker to display a PDF. Is it possible with Adobe's PDF Embed API to take a file located on a local file share and display the PDF?
I'm thinking I need to create a file promise but I'm not sure how to create that.
Unless you can make a network request to load the PDF, the answer is no. Browsers generally can't read from local files unless a user action actually picks the file. If your local share can be made accessible via HTTP, then you would be good to go.

Imported packaged files ".key .numbers .pages" from iCloud using UIDocumentMenuViewController are not opening in UIWebView

Hi I am trying to display a packaged file say .key/.pages/.numbers file to user in a UIWebView but I cant. The keynote file was created using a Keynote app from my iPad recently. I imported that file to my app using UIDocumentMenuViewController from iCloud. I tried to look into the file attributes and it turn out that the file imported is actually a "directory" not single file. Inside, it has some contents. Can anybody tell me how to go from here?
I had the same problem. iWork files are zipped bundles but for some reason importing from iCloud unzips the contents first, whearas copying from the app directly via Open in ... from Number (or Pages or Keynote) works perfectly.
So what you need to do is test if the result of import is a directory, and if so zip the directory into a single file and keep the correct file extension (.number pages or .key).
This seems like a hack but it works and is best workaround I've been able to find
In Swift you can use SSZipArchive as an easy way to zip a directory

Download / upload file using the Add-On SDK

I am currently trying to download a small binary file from the web, in order to upload that to another website, both using the API.
Previous versions seemed to have the "file" API module for such purposes, but I can't see anything similar as of the latest (1.14).
The file to be downloaded would be saved in some form of cache (browser cache, preferably), its path stored somewhere, to be then uploaded to another URL via POST.
How would I go about it, when the process should happen completely in the background?
I checked out the how to download a file page, but can't figure out where to download.
Is there a variable URI for the "Downloads" directory, and does a regular Add-On has write privileges in it?.
This is important, because the add-on must be able to function properly on various platforms.
You can use the pref, browser.download.lastDir, which should work for windows/mac as it will be saved in the OS format. However the pref may not always be set if the person has never downloaded anything before. In that case you'll have to build the directory yourself.
var dir = require("sdk/preferences/service").get('browser.download.lastDir');
To build the directory yourself you're going to have to go a little deeper. Check this article on MDN about File I/O which has examples. The DfltDwnld key should give you the directory you want.
Your add-on will have write permissions to everything Firefox has write permission to.

With filepicker.io, is there a way to get the original file path?

I am using filepicker.io and specially computer as main service.
I would like to get the original file path of a file uploaded through the API.
For example, if I upload a file located at /my/path/in/my/computer/file.zip, I will get in the FPFile object the filepicker.io URL but not the original file path.
Is there a way to get it ?
PS: I have tried to retrieve the stat of the file too without success.
Due to browser security limitations, the real local path of the file is never exposed to the javascript application. For more information, see http://davidwalsh.name/fakepath

Accessing files in Documents folder via jqtouch in iphone app

I was able to save some files in the Documents folder on my app. How can I access them on the phonegap side of things with jqtouch/javascript/html. I want to do something like:
$('#intro').attr('src','../../Documents/logo.png');
But, apparently, it's not letting me go up all those directories outside of www.
How can I resolve this?
There is a bundle file reader plugin, but it seems to read the contents, not reference it.
https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/BundleFileReader
Not sure you can do what you are asking about. Perhaps you could use the PhoneGap File API to save the files somewhere within your www dir instead? Then they would be available via html/js.