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)
|
newName = u"{0}{1}".format(orig_path, file_name)
|
||||||
|
|
||||||
with open(newName, 'wb') as f:
|
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:
|
except Exception as e:
|
||||||
code = 0
|
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:
|
try:
|
||||||
Filemanager.check_access_permission(dir, path)
|
Filemanager.check_access_permission(dir, path)
|
||||||
|
|
|
@ -1624,7 +1624,7 @@ if (has_capability(data, 'upload')) {
|
||||||
complete: function(file) {
|
complete: function(file) {
|
||||||
if (file.status == "error") {
|
if (file.status == "error") {
|
||||||
var alertifyWrapper = new AlertifyWrapper();
|
var alertifyWrapper = new AlertifyWrapper();
|
||||||
alertifyWrapper.error(lg.ERROR_UPLOADING_FILE);
|
alertifyWrapper.error(lg.upload_error);
|
||||||
}
|
}
|
||||||
$('.upload_file .dz_cross_btn').removeAttr('disabled');
|
$('.upload_file .dz_cross_btn').removeAttr('disabled');
|
||||||
getFolderInfo(path);
|
getFolderInfo(path);
|
||||||
|
|
|
@ -1490,14 +1490,15 @@ def load_file():
|
||||||
errormsg=gettext("File type not supported")
|
errormsg=gettext("File type not supported")
|
||||||
)
|
)
|
||||||
|
|
||||||
with codecs.open(file_path, 'r', encoding=enc) as fileObj:
|
def gen():
|
||||||
data = fileObj.read()
|
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(
|
return Response(gen(), mimetype='text/plain')
|
||||||
data={
|
|
||||||
'status': True, 'result': data,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/save_file/', methods=["PUT", "POST"], endpoint='save_file')
|
@blueprint.route('/save_file/', methods=["PUT", "POST"], endpoint='save_file')
|
||||||
|
|
|
@ -2542,11 +2542,9 @@ define([
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
if (res.data.status) {
|
self.gridView.query_tool_obj.setValue(res);
|
||||||
self.gridView.query_tool_obj.setValue(res.data.result);
|
self.gridView.current_file = e;
|
||||||
self.gridView.current_file = e;
|
self.setTitle(self.gridView.current_file.split('\\').pop().split('/').pop());
|
||||||
self.setTitle(self.gridView.current_file.split('\\').pop().split('/').pop());
|
|
||||||
}
|
|
||||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||||
// hide cursor
|
// hide cursor
|
||||||
$busy_icon_div.removeClass('show_progress');
|
$busy_icon_div.removeClass('show_progress');
|
||||||
|
|
Loading…
Reference in New Issue