Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to know the name of a file that is being downloaded or to set a name before download?

Tags:

puppeteer

I'm downloading a ton of files using puppeteer, but I need to know each file's name before or after download is complete. Watching the folder for file change doesn't solve my problem, due to lots of processes downloading files at the same time and having now way to match them.

I've been trying to set a custom path for download for each file, but Puppeteer does something weird that some downloads go to that folder and others to /Downloads.

So, I would like to know if there's a way to know the name before download or to set the name of the file before downloading. This way I can properly match it through code.

Note: files are downloaded via JS i.e. when a button is clicked. No way to know file name via scraping due to it being auto-generated.

like image 501
Carlos Ortiz Avatar asked Jun 11 '19 23:06

Carlos Ortiz


People also ask

How can I tell where a downloaded file came from?

Right-click the downloaded in Finder, and then click the “Get Info” command. You can also select the file and then press Command+I. In the Info window, expand the More Info section. You should see two URLs: the exact one for the download, and also the site you where clicked the link.

How do you know file is downloaded or not?

To find downloads on your PC: Select File Explorer from the taskbar, or press the Windows logo key + E. Under Quick access, select Downloads.

How do I change a file name before downloading it?

Method 1: You can use Wait for Download activity to download a file, then you can use Rename activity to rename it. Method 2: To rename a file before downloading, you can use Http request to download and name the file. You can configure download file name in “Download Resource”.

Does the owner of a website know if I download files?

That's basically the minimum part of what the owner will know about those who download files from their servers: an IP address. Now, if you also happen to have an account at that site and are lo I’ve never tried SiriusXM – what makes it so good? Yes, if your ip address is not behind a proxy. Will it give exact details of your name and etc, no.

Why do I need to keep track of the original name?

By keeping track of the original file name I can communicate with the file's owner without them ever knowing I changed the file name on the back end. That is, until they go do download the file. In that case they're prompted to download a file with a unfamiliar name.

Can Google know who you are if you download files?

If you'd download the file from Google's servers then Google will probably know who you are because you also use GMail and happened to be logged in the Google services. Same with Facebook and Twitter, who also know a lot of information about various people. Thus, they can connect your IP address to other parts of your account and know who you are.

What happens to your data when someone downloads a file?

Generally speaking, when someone downloads a file, they have made a bit-for-bit copy of the original, and those bits are no longer under your control, at least not as a simple collection of bits. One approach is the one that Microsoft takes with Rights Management Server.


1 Answers

If the download is triggered by the page, this is done by using the Content-Disposition header. Very likely, the header also includes the file name as part of the header.

Example

Below, an example for the header:

Content-Disposition: attachment; filename="name_of_download.ext"

In order to read the filename, you can therefore check out the name of the file by looking at response.headers(). In the following example I'm using a regular expression after that to extract the file name:

const contentDisposition = response.headers()['content-disposition'];
const matchFilename = contentDisposition.match(/filename="(.*)"/);
if (matchFilename) {
  const filename = matchFilename[1];
}

Non-ASCII characters

Depending on the files you are downloading, you also might want to check out this stackoverflow answer regarding the encoding for non-ASCII file names.

like image 55
Thomas Dondorf Avatar answered Jan 02 '23 22:01

Thomas Dondorf