Class: DownloadItem
Process: Main
This class is not exported from the 'electron'
module. It is only available as a return value of other methods in the Electron API.
DownloadItem
is an that represents a download item in Electron. It is used in will-download
event of Session
class, and allows users to control the download item.
Event: ‘updated’
Returns:
event
Eventstate
String - Can beprogressing
orinterrupted
.
Emitted when the download has been updated and is not done.
The state
can be one of following:
progressing
- The download is in-progress.interrupted
- The download has interrupted and can be resumed.
Event: ‘done’
Returns:
- Event
state
String - Can becompleted
,cancelled
orinterrupted
.
Emitted when the download is in a terminal state. This includes a completed download, a cancelled download (via downloadItem.cancel()
), and interrupted download that can’t be resumed.
The state
can be one of following:
completed
- The download completed successfully.cancelled
- The download has been cancelled.interrupted
- The download has interrupted and can not resume.
The downloadItem
object has the following methods:
downloadItem.setSavePath(path)
path
String - Set the save file path of the download item.
The API is only available in session’s will-download
callback function. If path
doesn’t exist, Electron will try to make the directory recursively. If user doesn’t set the save path via the API, Electron will use the original routine to determine the save path; this usually prompts a save dialog.
downloadItem.getSavePath()
Returns String
- The save path of the download item. This will be either the path set via downloadItem.setSavePath(path)
or the path selected from the shown save dialog.
downloadItem.setSaveDialogOptions(options)
downloadItem.getSaveDialogOptions()
Returns SaveDialogOptions
- Returns the object previously set by downloadItem.setSaveDialogOptions(options)
.
downloadItem.pause()
Pauses the download.
downloadItem.isPaused()
Returns Boolean
- Whether the download is paused.
downloadItem.resume()
Resumes the download that has been paused.
Note: To enable resumable downloads the server you are downloading from must support range requests and provide both Last-Modified
and ETag
header values. Otherwise resume()
will dismiss previously received bytes and restart the download from the beginning.
downloadItem.canResume()
Returns - Whether the download can resume.
downloadItem.cancel()
Cancels the download operation.
downloadItem.getURL()
Returns String
- The origin URL where the item is downloaded from.
downloadItem.getMimeType()
Returns String
- The files mime type.
downloadItem.hasUserGesture()
Returns Boolean
- Whether the download has user gesture.
downloadItem.getFilename()
Returns String
- The file name of the download item.
downloadItem.getTotalBytes()
Returns Integer
- The total size in bytes of the download item.
If the size is unknown, it returns 0.
downloadItem.getReceivedBytes()
Returns Integer
- The received bytes of the download item.
downloadItem.getContentDisposition()
Returns String
- The Content-Disposition field from the response header.
downloadItem.getState()
Returns String
- The current state. Can be progressing
, completed
, cancelled
or interrupted
.
Note: The following methods are useful specifically to resume a cancelled
item when session is restarted.
downloadItem.getURLChain()
Returns String[]
- The complete URL chain of the item including any redirects.
downloadItem.getLastModifiedTime()
Returns String
- Last-Modified header value.
downloadItem.getETag()
Returns String
- ETag header value.
downloadItem.getStartTime()
Returns Double
- Number of seconds since the UNIX epoch when the download was started.
downloadItem.savePath
A String
property that determines the save file path of the download item.