Resuming file upload - javascript

I am writing a single page application where the user can upload photos. But I am not clear about a situation in which while user is uploading multiple photos, he closes the browser. Now when he logs in again, the browser should automatically resume the upload from the last uploading image. Is this possible? How?
I cannot store the image in local storage and upload since the image
size can go beyond the local storage capacity.
I cannot store the file path and resume by using the file path.
Since the browser security won't allow me to.

When you are working with an SPA and the browser is closed the data in the SPA is lost. Even if you want them to resume uploading(which browser security won't allow) using the path there are 2 case scenario:
1)Does the file actually exist in the old path(No)
2)What if the user deleted or moved the file.
Anyways this should not be done using browser. Better to use a tool with 3rd party. like if you shut down the client, then the client will stop sending data to the server.
If you want to upload large files on a regular basis and not have the process be interrupted by people forgetting that their browser is uploading in another tab and quitting, then you might consider using a stand-alone upload tool (http://www.flickr.com/tools/uploadr/)
However It can be achieved by designing a special type of browser.

Related

How to download a file using javascript?

Hi is there any chance to download a file into local system without displaying downloading process at the front end ?
I am trying as below
var f = document.createElement("iframe");
f.setAttribute("id", "theFrame");
document.body.appendChild(f);
document.getElementById("theFrame").location = 'http://www.example.com/yourfile.doc';
I am able to download the file but it was displaying in the front end of the browser as the file is getting download.
No. That is not possible.
A web site is by definition untrusted. And you don't want to let untrusted web sites make changes to your system, even if it is 'just' a file download (which could be potentially dangerous since it can contain a virus for example).
Therefore a browser will show the download to the user as it thinks it is appropriate. Nothing you can do about that.
(As you have built already, you can download it without permission, you just can't hide the download)
Not possible. When the browser detects a file download it will show up in the download bar and you can't (at least you shouldn't be able to) stop this - it's the way the browser works and has nothing to do with javascript/php code.
I also can't think of any use case where you would want to hide this from your user, except for malicious intent (like a virus).

Google Chrome extension - download, move and delete files

I am trying o make app for my work (will be used only in my office) and among other things I need way to download file (it will be always one ODT and one txt document which will be initiated by clicking on button by user, on specific page - standard download) from our local server. Those two files are created on server and then sent to download to user which requested it, so that part is simple as any other web page which offers you download.
But after download is finished I need somehow:
1) automatically open ODT (openOffice writer) file, so user can continue editing it. What will happen next is not important...
2) automatically move TXT file to specific folder on users disk (this is needed because that specific folder is monitored by our special printer and whenever printer detects file in that folder it automatically starts printing). Setting default chrome download folder as that monitored folder is not options - so I NEED to move TXT file automatically after download to that monitored folder.
3) After first two actions are finished I need to clean default download folder (foldere where chrome downloads by default) because it would be full of those files and they are not needed anymore.
Now, it would be great if I could accomplish it just with javascript but as I know there is no way to manipulate files on local system without displaying dialog to user - so this is not option.
I figure it out that this part could be done by chrome extension, which is acceptable solution because this application will be used only in my office. But I am not sure how and if it is really possible to accomplish what I want so I need your help.
P.S.
It is important that after user click "Download" on page to download ODT and TXT file, there is no other windows, dialog and other "questions" by browser but everything after that should go automatically.
Thank you!
Yes, you can do those tasks with chrome.downloads API, as long as you can accept a subfolder of the Downloads folder as a target for your printer. You cannot download in an arbitrary folder, I'm afraid.
After a download you initiated with chrome.downloads.download finishes, you can initiate opening it with chrome.downloads.open(downloadId).
You can initiate a download into a subfolder by supplying a relative path to chrome.downloads.download (note the / slash instead of \): printout/file.txt.
You can remember the download id's and clean up afterwards with chrome.downloads.removeFile(downloadId).
Please take note of the permissions you need to add, they are quite fine-grained for this API.

Force ask where save file before download

I have an embedded system with a web server Mongoose, I have to allow the client to download some log files generated at runtime, I have a problem during the download, in practice, the browser first downloads the file and then asks where to save the file .
The behavior is unpleasant because the download takes a few seconds and the client does not understand what's going on.
Is there any option, for example, in the header of the file, to force the browser to ask before making the download where to save the file?
Thanks.
it is not up to you to decide how the client's browser is behaving.
if the browser is set to save the file automatically in a specific place, then there is nothing you can do.
your only workarounds is to either upload your file somewhere and suggest the viewer to right-click a download link that points to the file, it will open the dialog,
or suggest the viewer to change browser settings,
or write a browser extension that does that and offer viewers to install it.

JavaScript downloader

I want to allow a web site users to be able to download files from my site, but with the help of a client-side downloader with an ability to continue an interrupted download.
For example, I want to sent a person a file with a size of 30+ Meg. I want the user to have the best downloading experience, so I can't afford him downloading 25 Meg and then getting the download dropped due to the network problems on his side.
Therefore, I want to have a javascript downloader rendered on a download page, that will show the actual client-side file delivery, and when it is downloaded, to give an ability to a user to save the file.
Or is it not possible due to the fact that javascript won't be able to open a save file dialog and save to a file system?
I'm afraid that is not possible with JavaScript and that's why:
To continue downloading from the certain point you should send to the server the position number to start downloading from. And as JavaScript has no access to local file system, you can't get that position.
UPD: it seems that I was too hurrying with the reply.
The file size can be gotten using the HTML5 File API and after getting the file size you can pass it to the server which should support the partial downloading.
But anyway, after downloading another part of the file you should sew two pieces together in some way; standard web browser dialog will only suggest to overwrite the file.
UPD2: to work with files in some Internet Explorers you can use FileSystemObject:
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
I'd look into making a plugin or extension. Like those DownloadThemAll extensions for firefox and Google chrome. Another alternative would be to use Flash, either alone or integrating it with javascript like hinted here: http://www.communitymx.com/content/article.cfm?cid=0922A

How to resume a broken upload in HTML5

I am trying to add resume functionality to html5 file uploader.
I need to be able to resume after browser was closed (and reopened) and I lost the file object, I do not want the user to drag/open the file again.
Until now I used java applet to do it but I was hoping to find an html5 solution for this problem.
I thought about saving the files in local storage but they are too big.
Is there a way to save only the file object the path or any other information that might help me reopen the file without asking the user to reopen the file?
You might want to try out Resumable.js - JavaScript Library Providing Multiple Simultaneous, Stable And Resumable Uploads Via The HTML5 File API (or its domain www.resumablejs.com).
Resumable. js a JavaScript library providing multiple simultaneous, stable and resumable uploads via the HTML5 File API.
The library is designed to introduce fault-tolerance into the upload of large files through HTTP. This is done by splitting each files into small chunks; whenever the upload of a chunk fails, uploading is retried until the procedure completes. This allows uploads to automatically resume uploading after a network connection is lost either locally or to the server. Additionally, it allows for users to pause and resume uploads without loosing state.
Resumable.js relies on the HTML5 File API and the ability to chunks files into smaller pieces. Currently, this means that support is limited to Firefox 4+ and Chrome 11+.
sorry, it is not possible. The link between the file and the browser, that you can access with javascript (the FileURL) is destroyed after closing the window (and for sure, when closing the browser). You could save the name of the file and the amounts/parts uploaded and request the user to upload that file again, continuing from where he left off, but not automatically, without the users consent.
/Edit: Why the negative votes? Please leave a comment so I know what I said wrong! The question is about how to resume an upload when the user closes the browser. And that isn't possible. It is possible to stop/resume an upload while the Browser remains open and connection is lost, but not when the user closes the browser (references are lost). You could however copy the file to a temporary filesystem and then resume upload from there but that needs user consent and its limited to the amount of space the user provisions you to use.
This is possible with newer browsers(Chrome, Firefox).
The youtube uploader is a good example.
http://support.google.com/youtube/bin/static.py?hl=en&topic=1719827&guide=1719823&page=guide.cs&answer=1672758
http://www.youtube.com/watch?v=L5ebSn9HgJ4
I'm not entirely sure how their implementation fully works, but it is possible.

Categories

Resources