久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Electron - 將文件下載到特定位置

Electron - Download a file to a specific location(Electron - 將文件下載到特定位置)
本文介紹了Electron - 將文件下載到特定位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要將文件下載到我的 Electron 程序中的特定位置.
我嘗試實現 此 API 但失敗了.
然后我嘗試實現官方API,但不知道如何實際啟動下載文件.

I need to download a file to a specific location in my Electron program.
I tried implementing this API but failed.
Then I tried implementing the official API, but couldn't realize how to actually start downloading the file.

如何將文件下載到特定位置,例如 C:Folder?
謝謝!

How can I download a file to a specific location, say C:Folder?
Thanks!

推薦答案

我最終使用了 electron-dl.
發送下載請求(來自 renderer.js):

ipcRenderer.send("download", {
    url: "URL is here",
    properties: {directory: "Directory is here"}
});

main.js 中,您的代碼如下所示:

In the main.js, your code would look something like this:

const {app, BrowserWindow, ipcMain} = require("electron");
const {download} = require("electron-dl");
let window;
app.on("ready", () => {
    window = new BrowserWindow({
        width: someWidth,
        height: someHeight
    });
    window.loadURL(`file://${__dirname}/index.html`);
    ipcMain.on("download", (event, info) => {
        download(BrowserWindow.getFocusedWindow(), info.url, info.properties)
            .then(dl => window.webContents.send("download complete", dl.getSavePath()));
    });
});

下載完成"監聽器位于 renderer.js 中,如下所示:

The "download complete" listener is in the renderer.js, and would look like:

const {ipcRenderer} = require("electron");
ipcRenderer.on("download complete", (event, file) => {
    console.log(file); // Full file path
});

如果您想跟蹤下載進度:

main.js中:

ipcMain.on("download", (event, info) => {
    info.properties.onProgress = status => window.webContents.send("download progress", status);
    download(BrowserWindow.getFocusedWindow(), info.url, info.properties)
        .then(dl => window.webContents.send("download complete", dl.getSavePath()));
});

renderer.js 中:

ipcRenderer.on("download progress", (event, progress) => {
    console.log(progress); // Progress in fraction, between 0 and 1
    const progressInPercentages = progress * 100; // With decimal point and a bunch of numbers
    const cleanProgressInPercentages = Math.floor(progress * 100); // Without decimal point
});

這篇關于Electron - 將文件下載到特定位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 日韩在线播放中文字幕 | 在线三级电影 | 日本成人午夜影院 | 2019天天干天天操 | 99热国产在线播放 | 国产精品一区二区在线 | 日韩一区二区免费视频 | 成人二区 | 偷拍亚洲色图 | 波多野结衣电影一区 | 99热首页 | 国产精品日韩欧美一区二区三区 | 精品蜜桃一区二区三区 | 日韩中文字幕网 | 精国产品一区二区三区 | 国产美女自拍视频 | 精品蜜桃一区二区三区 | 日日操视频 | 久久精品一 | 成人小视频在线观看 | 欧美一区二区在线观看 | 国产乱码精品一品二品 | 国产日韩精品视频 | 精品一区二区久久久久久久网精 | 97精品视频在线观看 | 日本又色又爽又黄又高潮 | 视频一区二区中文字幕 | 亚洲黄色av | 九九色综合 | www.国产日本 | 夜夜精品浪潮av一区二区三区 | 日韩高清中文字幕 | 无码日韩精品一区二区免费 | 盗摄精品av一区二区三区 | 午夜影视 | 色男人的天堂 | 在线不卡一区 | 免费视频二区 | 亚洲综合区 | 亚洲视频二 | 亚洲欧洲成人在线 |