Saring code sample will be helpful to figure out the issue. Are you using download tag in your html. From what I understood, as examples use ipcMain , I passed a message from the renderer. Add a comment. Active Oldest Votes. Improve this answer. How to speed downloading up! I wanted it to work like idm. And how to pause and resume. The thing is, I have to call the API from the renderer page, so I have to pass messages and things like that.
When I called. I implemented this code, But I need to give the local computer folder path from which I need to download the files. It gives me error "cannot read property 'get typeof null ".
Can you please help! I am also facing the same problem and thanks to you. How do I get through this? To allow a user to download a file in an Electron application, you need to do the following: Get either the default session or the session of the user from the partition. See Session Once you have an instance of the session object, you can then listen for events like will-download which is emitted on Session object when the user clicks on a link to download a file and the file is going to be downloaded.
You have 2 choices regarding that: You can either ask the user to set the download location Default behavior You can set the download location for the file using item object, that you get from the event will-download.
Use the method setSavePath on the item object. Akshay Anurag Akshay Anurag 1 1 gold badge 6 6 silver badges 27 27 bronze badges. Additionally, a download has a number indicating the download progress from 1 to Once a download is done, it will contain a Blob as its content - until then this property is not available, therefore null. Now we want to abstract from specific HTTP events to our newly defined data structure. This way our components can be decoupled from the underlying network protocol.
Since we're dealing with multiple events coming in over time, a RxJS operator is well suited here - so let's create one! The first step for this will be the creation of type guards helping us to distinguish different HTTP events. This way we can access event-specific fields in a type-safe way. They both contain the discriminator field type allowing us to easily return a boolean for the type assertion in our guards. The guards can be used with a simple if-statement, however, TypeScript will narrow the event type inside the statement block for us:.
Based on these guards we can now create our custom operator. It'll leverage scan , an operator that allows us to accumulate state for successive values coming through an observable. It takes up to two arguments: First, we provide an accumulator function which will compute the next Download state from the previous one and the current HttpEvent.
Second, we'll pass a seed to scan representing the initial Download state. This seed will represent our download being pending without any progress or content:. Our accumulator will use the previously defined guard to update the Download state over time with information from the HTTP events:. When we encounter a HttpProgressEvent , we calculate the progress based on the number of bytes already loaded and the total bytes.
A download is done when we receive a HttpResponse containing the file contents in its body. When receiving any other events than HttpProgressEvent or HttpResponse , we won't alter the download's state and return it as it is. This way, for example, we can keep the information in the progress property while other events that won't allow us to compute the progress can be ignored for now.
Anything unclear? Let's finally define our custom operator that's using scan with our accumulator and seed :. Notice that this download operator accepts an optional parameter saver. Once a HTTP response is received, this function is invoked with the download content from inside the accumulator.
This allows us to pass in a strategy for persisting the download to a file without directly coupling the operator to FileSaver.
By keeping FileSaver. The download operator can be tested without somehow mocking the saveAs import see here for corresponding tests. If we apply the same pattern to the service, we'll be able to test it just as easy. Use the method setSavePath on the item object. Related How to setup next. Drupal - Why does js click function run multiple times?
Drupal - Get current language of Drupal 8 in javascript? Drupal - How to load content in a div with ajax? Drupal - Loading a library only for the front page Drupal - How can I create a node via ajax call?
0コメント