Download external pdf files to chrome packaged app's file system - google-chrome-app

Is there any way to save pdf files from server to chrome packaged app?
In my chrome packaged app, i have some thing like this,
Download
when user clicks on this hyper link, i should able download that pdf file into my chrome packaged app file system.

There's nothing special about downloading PDF files. Use XMLHttpRequest to download a file, and then use the file APIs to either write it to a sandboxed file, or to an external file whose FileEntry you get with chrome.fileSystem.chooseEntry.
Once downloaded, you can display the PDF in a webview or provide a link to open it in an external browser if you first convert it to a data URL with FileReader.readAsDataURL. (You can't reference the downloaded file as file:// URL.)
(Chrome Apps should not be referred to as "packaged" apps, as the latter term refers to a now-obsolete legacy app technology.)
Update: To save the downloaded blob to a file:
// Save a blob in a FileEntry
// (e.g., from a call to chrome.fileSystem.chooseEntry)
function saveToEntry(blob, fileEntry) {
fileEntry.createWriter(
function(writer) {
writer.onerror = errorHandler; // you supply this
writer.truncate(0);
writer.onwriteend = function () {
writer.write(blob);
writer.onwriteend = function () {
// blob has been written
};
};
},
errorHandler // you supply this
);
}

Related

IONIC 4: How to call iOs file resource from custom script within app

Here is the situation:
Ionic 4: (cli-5.2.7)
XCode 10.3
We have a custom eReader that lives in our assets folder.
When we want to download an eBook from our server and read it, we download the file and save it using the Native File plugin.
When we start up the reader, we send it the container in which we want the reader to be created and built, and an internal url to the file resource we want to read.
After window.Ionic.WebView.convertFileSrc, the file ref looks like:
ionic://localhost/_app_file_/var/mobile/Containers/Data/Application/[APP-ID]/Library/NoCloud/[BOOK-ID]/vol-001-chapter-006.xhtml
The reader will then build the iframe and send a simple XMHttpRequest to the provided url, then place the resulting html into the iframe.
The problem is that it only works on first load of the eBook from our server
I can see the file being downloaded, and written to its own folder in the apps file system (File.dataDirectory).
When I debug the XMLHttpRequest in our eReader.js, I can see the call being made to the resource and the HTML returning to the request, which is then rendered on the page.
BUT, if I close the app, reopen it, and try to access the already-downloaded book, the XMLHttpRequest in our eReader.js returns nothing.
I can verify that the file exists at the resource location after a reload, but the XMLHttpRequest acts like it cannot find anything at the provided location.
AND, this is only on iOs. Android works as intended.
My questions is, what am I missing? Is this something to do with the iOs permissions or persistence?
Any help would be appreciated.

PLupload can add files but blocks when I choose to upload

I am using Gravity Advanced Files uploader plugin for wordpress which use PLupload for file uploads.
I want it to allow .bmp and .dcm files to be uploaded. I was able to change the settings to allow those files types to be added with plupload by adding the file extension and also to the mime type list. But when I press start upload it comes back with those files as having a "file type error".
Resolved. The issue was actually the wordpress media library blocking those file types. I added this code to me funcitons.php file and problem solved.
add_filter( 'upload_mimes', 'my_myme_types', 1, 1 );
function my_myme_types( $mime_types ) {
$mime_types['dcm'] = 'application/dicom'; // Adding dicom images extension
$mime_types['bmp'] = 'image/bmp';
return $mime_types;
}

Parsing Contents of Dropbox File in JavaScript Web App

Is it possible using the Dropbox JS SDK to create a JavaScript web application that is able to parse the files in a user's Dropbox? In my use case, the user has some JSON files that I would like to parse and preview in the browser. Will the filesDownload(arg) method allow for this type of application, or is it only able to download the file to the user's machine?
The download methods, such as filesDownload and sharingGetSharedLinkFile return the file content directly as a Blob, as seen in the download example.
As long as you can use a Blob to do what you want, this should be possible.

openURL on local file in temporary directory does nothing

I'm saving a downloaded PDF file to a temporary directory on my device, and have the URL for the resultant file:
file:///Users/colinbasnett/Library/Developer/CoreSimulator/Devices/A057DDAD-B116-424B-8383-442321530EEC/data/Containers/Data/Application/A0AEF93A-5B1D-4CB4-B39F-F6DFECEDD9E9/tmp/FF5C09A9-45CD-454E-B55A-4F5CEBFEBC7F-24875-000014B657DC6436/23659.pdf
Where fileURL is a valid NSURL object representing the path above, I call this:
UIApplication.sharedApplication().openURL(fileURL)
and nothing happens.
Despite this, the following call returns true:
UIApplication.sharedApplication().canOpenURL(fileURL) // returns true
Ideally this would open in Safari or whatever the preferred browser application is. Interestingly enough, I can manually open Safari, paste that directory in the address bar and it is able to display the PDF.
I'm using Swift 2.2 (can't switch to 3 yet because dependencies have not been upgraded).
I think the problem is that openURL() wants to launch a separate application, but you're passing a file: URL that points to a file in your sandbox. I suspect UIDocumentInteractionController might be more what you're after.

Access downloaded pdf file path in HTML5 file system and display it in webview

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