Fix handline of large file uploads and properly show any errors that may occur. Fixes #2153

This commit is contained in:
Harshal Dhumal
2017-07-17 10:51:26 +01:00
committed by Dave Page
parent dcc74af87b
commit 8bbcf0ab36
4 changed files with 18 additions and 15 deletions

View File

@@ -1490,14 +1490,15 @@ def load_file():
errormsg=gettext("File type not supported")
)
with codecs.open(file_path, 'r', encoding=enc) as fileObj:
data = fileObj.read()
def gen():
with codecs.open(file_path, 'r', encoding=enc) as fileObj:
while True:
data = fileObj.read(4194304) # 4MB chunk (4 * 1024 * 1024 Bytes)
if not data:
break
yield data
return make_json_response(
data={
'status': True, 'result': data,
}
)
return Response(gen(), mimetype='text/plain')
@blueprint.route('/save_file/', methods=["PUT", "POST"], endpoint='save_file')

View File

@@ -2542,11 +2542,9 @@ define([
contentType: "application/json",
data: JSON.stringify(data),
success: function(res) {
if (res.data.status) {
self.gridView.query_tool_obj.setValue(res.data.result);
self.gridView.current_file = e;
self.setTitle(self.gridView.current_file.split('\\').pop().split('/').pop());
}
self.gridView.query_tool_obj.setValue(res);
self.gridView.current_file = e;
self.setTitle(self.gridView.current_file.split('\\').pop().split('/').pop());
self.trigger('pgadmin-sqleditor:loading-icon:hide');
// hide cursor
$busy_icon_div.removeClass('show_progress');