File Download using HTML 5 , Javascript and File API - html

Can we integrate the FileAccess API of HTML with normal download of Files using javascript.
We typically download a file by the below way:
var fileUrl='../File.doc';
window.open(fileUrl,'Downloading');
Now I believe that the file would be downloaded to tempFolder and the folder designated by us for download.
But is it possible for us to download the file to a sandboxed location as mentioned in WWC draft on HTML 5 File API.
If this is possible, I believe "need for a way to delete downloaded files" of my previous question would be solved.

There's a new download attribute you can add to links that tells the browser to download the resource rather than navigating to it. That downloads the file to whatever "Downloads" folder the browser uses by default. You cannot programmatically delete files that are downloaded. That would be a security risk.

Related

Chrome Extension- Change download folder for specific download

I just started to develop chrome extensions.
I want to create an extension in order to change the download folder for a specific download.
Can I do such thing?
if not,How can I change the default download folder before the downloads begin and then return it to the original value after the download ends?
You can't change the base Downloads folder - this setting is not anyhow exposed.
However, with chrome.downloads API you can put files in a subfolder of the user's Downloads folder.
You can either initiate the download yourself with chrome.downloads.download or use chrome.downloads.onDeterminingFilename request to intercept downloads from other sources.
You need to provide a relative path as a suggested name, e.g. "special/filename" to save into a subfolder special inside the Downloads folder.
Not an answer to the question but there is a Chrome Extension that can do it.
RegExp

Downloading files from Drive using alt=media with correct filename

I'm having trouble allowing files (non-shared) to be downloaded from a Google Drive account. I've created a listing using the php drive sdk and would like to provide authorised links to download the files using a generated access token. I've got downloads working with links like this:
https://www.googleapis.com/drive/v3/files/[fileid]?alt=media&access_token=[access_token]
The problem is that whenever a file is downloaded, it is named [fileid].[extension], rather than the real file name that appears in Drive.
I've tried adding the download="[real filename]" into the a link to suggest the correct filename, but it's being ignored in all the browsers I've tried.
I've got an alternative working that gets the file piece by piece server side and echoes it out as a file via php, but I'd prefer for downloads to be straight from Drive to the user.

Google Drive's "Download zip" adds .txt extension to plain text files

While experimenting with Google Drive SDK, I noticed a possibly unwanted behaviour of the Google Drive web interface.
When downloading an entire folder as a zip file, some files within that folder with MIME text/plain appear in the zip with added extension .txt, even if their extension is different on Drive.
For example, I had some .conf and .asc files, which ended being .conf.txt and .asc.txt in the resulting compressed archive, respectively.
The issue seems to exist only when using the "Download zip" feature: if the files are downloaded from the web interface one by one or using the SDK the extension is the original, as expected.
For Windows, you can download all your files from Google Drive, but instead of using the browser,
Go to https://www.google.com/drive/download/
Install Google Drive Sync executable
Log into whichever Google account that has your files
Open Windows Explorer and find where your Google Drive is mapped. You should see an icon like the following:
Double-click the Google Drive icon and navigate to the folder you wish to download. You should see links to your Google files, but non-Google files are downloaded and sync'ed with Google Drive Sync like the following:
Right-click to get the context menu and select the compression program. E.g., I have 7-zip installed, so I selected 7-Zip > Add to "your_file.zip"
This will compress the files without adding any weird file extensions. I haven't tried this on Mac or other compression programs. I believe this should work for any file extension since the files are downloaded to your hard drive.
Note, you can select which folders to sync, in case you have folders that were shared with you. This prevents huge downloads, large sync times and allows you to only download and sync only what you need.
Hope that helps.
The same situation with ZIP archives. I use the usual ZIP scheme to store files, but with a different extension *.tec. Before downloading the archive, Google rigidly renames the files to *.tec.zip!
I don't see any solution other than to programmatically check the files for the "zip" extension and rename them before opening. Of course, it's a problem that my product has to fix Google's bugs, but there it is...

How to view Google Drive file in browser

There is file stored in Google Drive. It is needed to open this file in browser. Google API JS library has method gapi.client.drive.files.get. It allows to get file resource which contains downloadUrl. This url allows to download file and save it on disk. Query string of url contains parameter e=download. If value of this parameter is changed to 'view' (e=view) then this url can be used in order to open gif file in browser. Nevertheles if the same is made with url to txt file then file is downloaded anyway.
Is there Goggle url which can be used to open txt file in browser? How to get such url?
Use the webContentLink:
"A link for downloading the content of the file in a browser using cookie based authentication. In cases where the content is shared publicly, the content can be downloaded without any credentials."

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.