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
Related
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).
I have developed a script for myself to read and process local text and csv files on my computer using recent Chrome or Firefox browsers with the filereader api. The script will work on the computer, even though it is not connected to the internet or a local webserver.
The reasoning behind this is to have a standalone text file interrogator, which will work on almost any computer, requiring only a browser to execute and display reasonably formatted output. similar to an awk type application.
I use the filereader api and it works well.
I do not properly understand the workings of the browser, so my question may be very stupid.
Is it possible that my script can somehow pass the filename to the script filereader api, without having to choose a file from input type=file field.
eg I have a file called addresses.csv and it resides in the same directory as my html/js file with the filereader api code.
I want to simulate the choosing of a file, without accessing my local directory and without using a webserver, but a dropdown box of predefined filenames would be even better.
No, for security reasons its not possible, because otherwise people could open arbitrary files on the computers of their visitors which is definitely not intended.
This specification also assumes that the primary user interaction is with the element of HTML forms [HTML], and that all files that are being read by FileReader objects have first been selected by the user.
See http://www.w3.org/TR/FileAPI/#security-discussion
No you cannot. Javascript cannot read your local filesystem without the use of a file input or drag and drop files (html5) as it would be vulnerable to malicious use.
There was a start of a filesystem api which Chrome has included. But you cannot read/write to just any place you want on the filesystem, you can only do so to a sandboxed area on the filesystem. Wither or not they will continue to have this in future versions of Chrome though I do not know.
It also appears the W3C itself has discontinued the file system api
I have a web page which asks users to select a zip file on their machine and upload it. It also asks for a destination on the server where the zip file should go. I want it to work in such a way that when they tell me where the file is on their machine and where it belongs on my server, then click "send," it should be sent to my server, placed in the designated directory, and unzipped.
I want to do this in just HTML and JavaScript. Is that possible? If so, how would I go about doing it?
You have to do this serverside; the client's browser cannot write to the file system of the server directly as it's a huge security risk.
In addition to that, not even HTML5 with it's File API can extract ZIP files. You need to do it on the server with PHP, or whatever language you're using.
If you just want to do things locally on the client, you could consider a Flash/Java/Browser extension, but I wouldn't recommend it for compatibility and performance reasons. Your best bet is to send a request to the server for it to process and send back. You're already serving the HTML page, so you can use the same server to process the ZIP file.
If, on the other hand, you want to write the ZIP file to the server, you have to do it server side for reasons stated in my first paragraph.
You can unzip/zip content within JavaScript using rawdeflate.
As other posters suggest, you cannot save directly to the local filesystem using a plain browser. You either need to echo the result back off the server (in which case it may as well unzip), or you can use Flash, for example, Downloadify, if it is installed.
Most modern browsers support FileAPI for loading from the local filesystem, certainly, Chrome, Firefox and Opera do. I haven't tested IE 9.
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.
I have a Firefox component for PDF signing that I invoke via Javascript. The problem is that this component outputs the signed PDF as a file on the user's filesystem - there is no way to get a byte[], stream or similar.
I need to post this signed PDF file back to the server. Is it possible to do this in plain Javascript, without additional Firefox components?
You can't do this without under intervention, this would he a huge security hole. Think about visiting a webpage and it being able to grab and upload any of your files without you doing a thing...you can see how this would be abused really fast.
You might be able to do this with a Firefox extension, I'm not sure of the security limitations it imposes (though I wouldn't be surprised if it disallowed this as well), but JavaScript would not be an option here.
There's no direct way to access data on a user's file system within a browser unless you're doing it through an extension. This would be a huge security risk.
If the file can be put into an <input type="file" /> element in Firefox, you can use JavaScript to automatically upload the data to the server without user intervention, but you would need something to initially get the file into the page's memory, not the file system.
Hell no - And for very good reason. You wouldn't want every Tom, Dick and Harry automatically grabbing all your files.
I believe it's the file input that needs user interaction. You can post the form automatically but you can't fill it in.
IMO your best bet is replacing the whole Firefox component with a single Java applet - I'd all but guarantee there's a Java project for PDF signing. Perhaps even Flash or Silverlight as long as you can do what you need with your PDF.