Is it possible to programmatically cancel/stop a started download from JavaScript? - javascript

Our application implements a custom download manager.
So actually this means that when a user starts a download of a resource he/she has the opportunity to cancel it through a UI button from the app, which actually sends some event to the server to cancel the downloading (the connection is disconnected and etc).
But since recently Chrome added auto-resume of failed downloads, so the same request is resumed to be downloaded again from the Chrome Download Manager, it's because Chrome cannot distinguish that the user/server intentionally canceled the HTTP connection so it revokes it again.
Currently, we download resources using IFrame, but once the download is started by the browser changing the IFrame's src attribute is not relevant anymore. I've tried to use <a href='...' download> but the issue is the same.
Maybe there's some API at least for Chrome? (There's actually such for Chrome extensions but this is not the case)

You cannot control the downloads that are managed by the download manager, of the browser.
If you want to control the download then you need to fetch the file JavaScript by e.g. utilizing the Streams API.
After you downloaded the Data you can pass that file to the download manager of the browser.
Each of those tasks can be solved in different ways.

Could you do something like add a unique key to the URL for each download request? When the user cancels the download, you invalidate the key so that the URL cannot be used again to download that resource - and in the process prevents Chrome from being able to resume the download.

Related

Open file in VLC from a href="path/of/file..WAV"

I'm looking a way to open a .wav49 on VLC with a link from my web app. Since files with .wav49 are not supported by <audio> tags. And I can't change the file type to a normal .wav or .mp3 due to several reasons.
The audio files are located in a shared folder on my server (which is a Windows Server 2016), so everyone on our network can access them.
The goal of my app is to make the audio file searching something easy.
I've been looking for options like change the format in backend and stream a .mp3 file to the audio tag or a plugin that allows to play .wav49 files but it seems that the easiest way is just to send the file to be opened on VLC.
The only I have for now is this
<a href="file:\\CENTRAL\path\audio.WAV">
I also tried with
<a href="file:\\CENTRAL\path\audio.WAV" download="test">
But neither works.
Only in Firefox, when I click the link ask me if I want to save it or just open it, but both of the options download the file. I don't want to download the file, I just want to launch an alert asking if the user wants to launch VLC and open the audio.
There are some examples of what I want to do, like roblox.com when a user click on the play button and he has the app installed, the browser launch the app on the local machine and gives the params of the game the user wants.
Another example is comodo remote control, when an user of comodo is in the web device manager and wants to begin a remote session, the user just click a button and an alert appears asking if the user wants to launch the remote control by Itarian app, if the user says yes, the app is launched in the local machine.
I found this Open video stream on VLC Player through the browser but it seems doesn't work anymore.
First of all, the standard path separator to be used here is a forward-slash, also if you want to link to a local file you need to use the file:/// prefix with three slashes. For network shares you would use two slashes: file://smbhost/path
So i would recommend you try the following:
<a href="file://CENTRAL/path/audio.WAV">
Hope this helps

Force the browser to download videos from third party website

I have this problem. I have a website which has URLs to videos from different website (not in my servers). What I exactly want when the user clicks on any of these link the video in remote website is downloaded. But what I have now when the user clicks on the link the video is open and show on the browser instead of download. I created a source code in ASP.net and C# that could force the browser to download the video, but the problem here is that my server should process the downloading operation to the browser, in other word that data should pass through my server to the client browser rather than from the third website to the client directly.
This will have two problems
it waste my server resources and effectiveness because the data should be processed through the server
it will increase the In and out bandwidth for my server and all the files are videos so it will be very costly.
What I want now, is there a way that enables me to force the browser to download the file directly from third party and without passing data through my server by using JavaScript, jQuery, or any client side techniques?
The html5 download attribute could help here. I haven't tested it personally but this blogpost says adding download should force a download on the browser side.
Example code:
Download

Javascript local file saving or onSave event to get saved filename

I'm developing a web app that needs some sort of filesystem access. Ideally I'd want to be able to "Open..." a file into the app and then "Save" the file back to local filesystem at the location that the user opened it from.
Currently, we use a java applet to achieve this functionality, but since java is going out of style, we're needing to do this with javascript and html5.
Obviously, this can't be done because of security reasons built into browsers, so I'm trying to somewhat emulate it.
I'm using the html5 file api to successfully import/open the files, so that's half the battle. The hard part is getting the saving feature. I'm getting close using an iframe and content-disposition, but problems arise when browsers are set to automatically download the files to a downloads folder... users may get confused and be unable to locate the file they just downloaded.
So, my question is this: is there some sort of onSave event or some kind of way for the browser's "Save As..." window to return at least the filename that the user saved the file under?
Also, I've looked into the filesystem/fileWriter html5 apis, but from my understanding they're limited to only a sandboxed area of the local filesystem and only available in chrome dev releases.
Any help would be appreciated!
No, there is no way to do that with pure JavaScript. You can manage to trigger a download with data URIs or an iframe with some headers but you can't circumvent the browsers' download managers.
You can either use a Flash or Java applet to handle the saving for you, or ask the user to right click on the link and do save as, then he might be able to choose the destination.
One popular option using Flash is Downloadify.

Download multiple files from remote server with a single user confirmation

I have a web page containing a list of pictures urls (can be more then 1000 items) and I want to enable a button for the user to click and download all of the files to the local hard drive.
The download process should ask the user for a directory to save the files in and then go ahead and download all files to that directory (if possible, creating sub directories inside). This should be done with a single user confirmation for the whole download process and avoid display the browser save dialog for each file.
Is there a way doing that? I am aware I can't use the standard HTTP protocol for the downloads and have to write some kind of control to do the job. The page is written in asp.net.
Downloading to the server, packing and sending to the user is not possible. The download has to be originated from the client machine.
You should update your question to include the requirements from your comment, because they make a huge difference. If the server cannot retrieve the files, because he doesn't have the right permissions, your only option is to run the code on the client side. There are several options how to do this, mostly depending on the clients and your coding skill:
Flash (Not sure about the security aspect of writing to the local file system, though)
Java Webstart (Disadvantage: Clients need to have the Java runtime installed)
Browser plugin/extension (Disadvantage: You can only support a subset of browsers and the page will not be immediately usable, as the plugin or extension needs to be installed first)
In all cases, you will have to write a tool, that retrieves the URL list from your server and starts downloading it.

How can I add a URL to the download manager in a Chrome Extension?

I've been working on an extension that checks for certain URLs in page content and lets the user put a button to automatically put these into the download manager. I've gotten everything I need, but how do I actually tell Chrome to put the URL into the download queue?
You can't, its not supported yet. There are no extensions for Chrome download manager.

Categories