Play a sound when download is ready - audio

The user selects some options then clicks "download". At that point, my php script starts preparing the file, and it can take 5-10 minutes before the file is ready and starts downloading. I want to notify the user with a sound that the download has started.
How can I do that?

According to this question:
Is there a way to detect the start of a download in JavaScript?
There is no programmatic way to detect when a download begins. That question is six years old now, so perhaps it is out of date, but I could not find any more recent information to contradict it.
An alternative approach would be to break the download process into two parts so that you can control when the actual data transfer begins:
Instead of initiating the download immediately, have the button send an AJAX request to the server asking it to prepare the file for download.
The server should not reply to the AJAX immediately, but should prepare the file and save it in a temporary file storage area with a unique generated name/ID.
Once the file is ready, the server should reply to the AJAX with the name/ID of the file.
On the client, the AJAX completion callback can play the sound, since it knows the download is about to begin.
It then uses window.open() to request the file from the server.
Now the server can respond with the appropriate headers as you used to do.
Finally, the server can delete the file from temporary storage (or just wait for a cron job to do it).

Related

"When A File Is Added Or Modified" trigger works for updated files but not created ones

I have a Logic App setup to monitor an ftp site that should trigger an action when uploading file. If I upload a file, change the original and upload again, trigger fires. Simply adding a file doesn't work.
Chances are your FTP client is preserving the timestamp of the last file change. Change this to have it trigger on newly added files, too.
FTP triggers work by polling the FTP file system and looking for any file that was changed since the last poll. Some tools let you preserve the timestamp when the files change. In these cases, you have to disable this feature so your trigger can work. Here are some common settings:
SFTP client
Action
Winscp
Go to Options > Preferences > Transfer > Edit > Preserve timestamp > Disable
FileZilla
Go to Transfer > Preserve timestamps of transferred files > Disable
Taken from HOW FTP TRIGGERS WORK.
Next to this, please be advised the actual trigger can have a delay that is up to twice the trigger's polling interval:
When a trigger finds a new file, the trigger checks that the new file is complete, and not partially written. For example, a file might have changes in progress when the trigger checks the file server. To avoid returning a partially written file, the trigger notes the timestamp for the file that has recent changes, but doesn't immediately return that file. The trigger returns the file only when polling the server again. Sometimes, this behavior might cause a delay that is up to twice the trigger's polling interval.

How to push a file saved to S3 to the frontend for download?

On my web app, I have a link which the user can click and download a CSV file containing some information.
When the user clicks on the download link, the app retrieves the records from DynamoDB and saves the results as a file to S3 in an asynchronous manner because it may take around 15seconds for the retrieval and saving to complete.
This would imply that when the user clicks on the download link, the file isn't available immediately on S3 to serve to the user.
In this case, how can I push the file to the user on the frontend as soon as the file has been saved successfully to S3 and ready for download?
For long-running jobs, a typical strategy is to track a sort of job ID in the database and update the database when it's done. For example, you might have an API that looks like this:
POST /jobs
{ ... job parameters ... }
And in response:
{
"id": "c7758160-12c2-448a-b982-1f613e4a9593"
"status": "processing"
}
Then later on, you can poll for a result:
GET /jobs/c7758160-12c2-448a-b982-1f613e4a9593
If the job status is done or whatever, then you can hit the appropriate S3 URL. (Perhaps your API server returns a signed URL.)
Instead of polling, you can also use server-sent events for the updates.
As an alternative method, for shorter running jobs, you can accept the API request, start the job processing, and only when it's done issue an HTTP 302/307 redirect to the S3 URL. I wouldn't do this for anything typically longer than a couple seconds though.

Is there any reliable way to capture file upload event in a chrome extension?

In my content script, I want to monitor which file a is getting uploaded to a web application.
I monitor "change" event for any "input:file" element. It works on any site (such as Gmail) that uses "input:file".
However sites like imgur, use SWFUpload mechanism. I tried to capture "fileQueued" event on element that I suspected to be swfupload. But that did not work.
How can I capture file upload event for sites that use swfupload?
Are there any other plugins that manage file uploading that I would need to take care in my content script?
Is there any generic mechanism to tackle this problem?
(I am aware of drag-n-drop mechanism, but I have not handled that case so far.
I have also read following relevant question on SO:
Grab file with chrome extension before upload)
It's probably worth your time to experiment with the chrome.webRequest API; it appears that the onBeforeRequest event contains info about file uploads. It's a complex API with extra parameters to addListener; read the docs thoroughly.

What technology can i use to run a method on a browser(client side) every time a user uploads a picture?

I have a custom function/method that needs to run on the browser (client side) every time the user uploads a picture to a web-server. This method modifies the image being uploaded and sends it to the server.
Currently the method is written in java so I thought of using an applet on the browser which could run this method and then send the modified picture to a servlet residing on the server, but the applet has certain disk read/write restrictions. I am aware of policies that can be used to grant these permissions to the applet but they need the users consent every time.
Also I want to avoid the applet .class file to be downloaded every time this page is viewed. So
Is there a cleaner approach to all this?
Are there any other technologies that can help me run this method on the browser ? (its ok if i have to rewrite the function in a different language)
Is writing a custom browser extension a good idea?
I think, that the JS using will be much better for this task.
One of JS image processing JS-library
, just for example.
How to invoke a servlet from JS example
Writing a browser extension is a really wrong way.

Is there a way to detect cancelled download?

Let's say I have a Spring MVC web application and it allows users to download a file. An email is sent at the same time as the file is sent to the user.
Is there a way to detect cancelled download so I could send the email only if the download has been successful?
You need a download script that serves larger files in seperate blocks. When the last block has been served, you can assume (there is no way to know with HTTP) that the complete file was received by the client.
Have a look at questions 157318 and 194579 on how to achieve this in PHP. Since you always use HTTP (or HTTPS) to serve the files, the same principles apply to your question.

Resources