Fix handline of large file uploads and properly show any errors that may occur. Fixes #2153
parent
dcc74af87b
commit
8bbcf0ab36
|
@ -886,10 +886,14 @@ class Filemanager(object):
|
|||
newName = u"{0}{1}".format(orig_path, file_name)
|
||||
|
||||
with open(newName, 'wb') as f:
|
||||
f.write(file_obj.read())
|
||||
while True:
|
||||
data = file_obj.read(4194304) # 4MB chunk (4 * 1024 * 1024 Bytes)
|
||||
if not data:
|
||||
break
|
||||
f.write(data)
|
||||
except Exception as e:
|
||||
code = 0
|
||||
err_msg = u"Error: {0}".format(e.strerror)
|
||||
err_msg = u"Error: {0}".format(e.strerror if hasattr(e, 'strerror') else u'Unknown')
|
||||
|
||||
try:
|
||||
Filemanager.check_access_permission(dir, path)
|
||||
|
|
|
@ -1624,7 +1624,7 @@ if (has_capability(data, 'upload')) {
|
|||
complete: function(file) {
|
||||
if (file.status == "error") {
|
||||
var alertifyWrapper = new AlertifyWrapper();
|
||||
alertifyWrapper.error(lg.ERROR_UPLOADING_FILE);
|
||||
alertifyWrapper.error(lg.upload_error);
|
||||
}
|
||||
$('.upload_file .dz_cross_btn').removeAttr('disabled');
|
||||
getFolderInfo(path);
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue