Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

[WIP] Add callbacks and feature to download files #14225

Merged
1 commit merged into from Dec 21, 2017

Conversation

vitallium
Copy link
Collaborator

This is re-implementation of my old branch of the feature to download files.

Per discussion: https://groups.google.com/d/topic/phantomjs/JChUakj--24/discussion

This pull request adds 3 new callbacks to a WebPage object: onFileDownload, onFileDownloadError and onDownloadFinished.

onFileDownload:

page.onFileDownload = function(url, data) {
  return 'path/where/to/save/file';
};

You can return a string with a file name, directory (in this case filename will be taken from HTTP headers), or an empty string (this will interrupt downloading).
Arguments:

  • url - source URL
  • data - array with download info: filename, size (file size) and contentType.

onFileDownloadError:

page.onFileDownloadError = function(error) {
}

Arguments:

  • error - a string representing an error occured.

onDownloadFinished:

page.onDownloadFinished = function() { }

This is a simple callback to notify the user about finished download.

TODO:

  • Tests!
  • Expose downloadFiles to the user.

Don't merge without tests.

Issue: #10052

@raff
Copy link
Contributor

raff commented May 5, 2016

This features works great but the "onDownloadFinished" callback is actually not implemented. Also, it may be useful if the onDownloadFinished callback would return some info (path of file downloaded) in case there are multiple downloads in progress.

raff added a commit to raff/phantomjs that referenced this pull request May 5, 2016
@raff
Copy link
Contributor

raff commented May 7, 2016

What kind of tests would you like to see ? I may be able to contribute.

@vitallium
Copy link
Collaborator Author

@raff do you have a test script? This callback works for me on Windows.

About tests. Tests must confirm that this feature works fine. Like, callbacks, downloads, etc.

@samir-mahendra
Copy link

@ariya @vitallium Are there any plans to merge this into master? File download is something I need.

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants