Hi, Please find attached patch to handle upload of large files and also to show upload error if error occurs instead of showing undefined.
-- *Harshal Dhumal* *Sr. Software Engineer* EnterpriseDB India: http://www.enterprisedb.com The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index 0e39fa9..2239cae 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -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) diff --git a/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js b/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js index d0eaf7a..5de8c1c 100755 --- a/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js +++ b/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js @@ -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); diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index d34836c..d51e241 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -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() - - return make_json_response( - data={ - 'status': True, 'result': data, - } - ) + 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 Response(gen(), mimetype='text/plain') @blueprint.route('/save_file/', methods=["PUT", "POST"], endpoint='save_file') diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js index 8a797ab..72904a9 100644 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js @@ -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');