Detect start of download start / file transfer from client side only

前端 未结 1 803
野的像风
野的像风 2021-01-21 05:32

I noticed that there is a question before asking how to \"Detect when browser receives file download\".

This requires the server to send a cookie in order to complete th

1条回答
  •  清歌不尽
    2021-01-21 06:24

    Edit: You can also ise an ajax call to get a base64 string of the zip and then clientside convert it to a blob in html5. But that requires to base64 encode the file server side and it increases the file size by around 33%.


    I would make an ajax call that checks is the file is already generated after starting the download with a timer:

    $.ajax({
        type: 'HEAD',
        url: 'generatedfileurl',
        success: function() {
            alert('File found.');
        },
        error: function() {
            alert('File not found.');
        }
    });
    

    Then when the file is found I'd wait a few seconds and then start download nr2 since I assume that file nr1 is already downloading since it has already been generated.

    It's far from ideal, I'd definitely recommend using cookies or something else serverside.

    0 讨论(0)
提交回复
热议问题