pub struct Download { /* private fields */ }Expand description
A file download.
Downloads are emitted via the page.on_download() callback or can be
obtained using page.wait_for_download().
§Example
// Downloads are obtained like this:
// let download = page.wait_for_download(async {
// page.locator("a.download").click().await?;
// Ok(())
// }).await?;
//
// // Get the downloaded file path
// let path = download.path().await?;
// println!("Downloaded to: {}", path.display());
//
// // Or save to a custom location
// download.save_as("./downloads/my-file.pdf").await?;Implementations§
Source§impl Download
impl Download
Sourcepub fn suggested_filename(&self) -> &str
pub fn suggested_filename(&self) -> &str
Get the suggested filename from the browser.
This is the filename that the browser suggested based on the Content-Disposition header or URL.
Sourcepub async fn path(&mut self) -> Result<PathBuf, NetworkError>
pub async fn path(&mut self) -> Result<PathBuf, NetworkError>
Get the path to the downloaded file.
This method waits for the download to complete if it’s still in progress. The file is saved to a temporary location by default.
§Errors
Returns an error if the download fails or is canceled.
Sourcepub async fn save_as(
&mut self,
dest: impl AsRef<Path>,
) -> Result<(), NetworkError>
pub async fn save_as( &mut self, dest: impl AsRef<Path>, ) -> Result<(), NetworkError>
Save the downloaded file to a custom location.
This method waits for the download to complete if it’s still in progress, then copies the file to the specified path.
§Errors
Returns an error if:
- The download fails or is canceled
- The file cannot be copied to the destination
Sourcepub async fn cancel(&mut self) -> Result<(), NetworkError>
pub async fn cancel(&mut self) -> Result<(), NetworkError>
Cancel the download.
This method cancels an in-progress download. If the download has already completed, this has no effect.