Chrome back button terminates upload stream unexpectedly

你说的曾经没有我的故事 提交于 2019-12-11 07:16:13

问题


I'm providing users form-based file uploads (one at a time) with ajax updates/progress bars. I want to give them a heads up if they navigate away that any current upload will be canceled. The following code achieves that goal except in Chrome (v.18). If you click the back button in Chrome the file upload stream is immediately terminated, throwing a org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly from the commons.fileupload library.

I couldn't find any information specific to this issue, but does anyone have any idea if this is something I'm just going to have to live with for now? Thanks.

Edit: I should add that Chrome does still shows the "Leave page" dialog, but at that point the upload is already stopped so the answer won't affect it at all. Clicking a link in Chrome does not stop the upload, and behaves as expected.

window.onbeforeunload = 
    function(event) {
        if (upload_in_progress) {
            var msg = "You are uploading a file." +
              "If you leave this page the upload " +
              "will be cancelled.\n\nLeave page?";
            var event = event || window.event;
            if (event) { event.returnValue = msg; }
            return msg;
        }
    };

回答1:


In Chrome and Safari functions attached to beforeunload event must always return string value (message displayed to user).



来源:https://stackoverflow.com/questions/10236146/chrome-back-button-terminates-upload-stream-unexpectedly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!