2017-01-27 7 views
0

ファイルをダウンロードしようとしていますが、中断され続けるため、理由がわかりません。私はそれが中断された理由をデバッグする方法に関する情報を見つけることができません。電子のダウンロードが中断し続ける

C:\ Users \ユーザーrnaddy \のAppData \ローミング\タキオン\ゲーム\ murware \超連鎖反応の\ web.zip

私は、ファイルを保存していますのはここ

ですここで

window.webContents.session.on('will-download', (event, item, webContents) => { 
    let path = url.parse(item.getURL()).pathname; 
    let dev = path.split('/')[3] || null; 
    let game = path.split('/')[4] || null; 
    if (!dev && !game) { 
     item.cancel(); 
    } else { 
     item.setSavePath(Settings.fileDownloadLocation(dev, game, 'web')); 
     item.on('updated', (event, state) => { 
      let progress = 0; 
      if (state == 'interrupted') { 
       console.log('Download is interrupted but can be resumed'); 
      } else if (state == 'progressing') { 
       progress = item.getReceivedBytes()/item.getTotalBytes(); 
       if (item.isPaused()) { 
        console.log('Download is paused'); 
       } else { 
        console.log(`Received bytes: ${item.getReceivedBytes()}; Progress: ${progress.toFixed(2)}%`); 
       } 
      } 
     }); 
    } 
}); 

は、上記の引き金となるというのが私のリスナーである:ここでは

ipcMain.on(name, (evt) => { 
    window.webContents.downloadURL('http://api.gamesmart.com/v2/download/murware/super-chain-reaction'); 
}); 

は、私が取得しています出力されます私はクロームでパスhttp://api.gamesmart.com/v2/download/murware/super-chain-reactionにアクセスしようとすると、私のダウンロードフォルダにうまくファイルのダウンロードを

127.0.0.1 api.gamesmart.com 

:私のコンソールで:

Received bytes: 0; Progress: 0.00% 
Received bytes: 233183; Progress: 0.02% 
Download is interrupted but can be resumed 

私は、ホストファイルを設定しています。だから、これを引き起こしているのは何ですか?

答えて

0

特定のディレクトリをダウンロードするように設定した場合は、フルファイルパスを使用して、ファイル名はitem.setSavePath()にする必要があります。ファイル名をdownloaditemオブジェクト(あなたの場合はitem)からフェッチするのが最善の方法です。 item.getFilename()を使用すると、現在のダウンロード項目の名前を簡単に取得できます。 here is the doc

また、頻繁に使用される公共システムのディレクトリパスを電子メールで取得するための良い方法があります。すなわち、app.getPath(name)メソッドを使用しています。 nameは、いくつかのディレクトリのための電子によってあらかじめ定義された文字列になります。 here is the doc

だから、あなたの完全なsetSavePath機能は、あなたの場合はapp.getPath("downloads") + "/" + item.getFilename()

だろう、あなたのファイルパスの抽出方法でOKであれば、あなたが不足している唯一のものは、ダウンロードパスの末尾にファイル名です。

もちろん、必要に応じて他の文字列をファイル名として使用できます。しかし、正しい拡張を置くことを忘れないでください。 :)

関連する問題