File Upload Problem

Hello All,
I’m Uploading files in custom folder in files.
It’s work perfectly on developer mode.

But doesn’t work on production mode.

In production mode all file are upload in files folder and most of tile file upload disconnect.
Please help me how can I fixed that.


Share what you see in your JS console. Seems like your socketio is not setup correctly.

Hello @rmehta
I got the problem.
below is my upload script’s some part.

MyClass = frappe.ui.BaseList.extend({
//Have some methods in this area.
upload_multiple_files: function (files /*FileData array*/, args, opts) {
       var me = this;
       var i = -1;

       // upload the first file
       // subsequent files will be uploaded after
       // upload_complete event is fired for the previous file
       $(document).on('upload_complete', on_upload);

       function upload_next() {
           i += 1;
           var file = files[i];
           args.is_private = 0;
           args.file_url = me.filter_list.get_filter('folder').value + '/' + (file.webkitRelativePath.length > 0? file.webkitRelativePath :;
           args.folder = args.file_url.replace('/' +, '');
           args.filename =;
           delete args.file_url;
           frappe.upload.upload_file(file, args, opts);
           frappe.show_progress(__('Uploading'), i+1, files.length);

       function on_upload(e, attachment) {
           if (i === files.length - 1) {
               $(document).off('upload_complete', on_upload);

I’m change the file_url and name.
Normally file name doesn’t contain folder name but I need with folder name.
So I set file name with folder name.
and I also replace write function.

def write_file(fname, content, content_type=None, is_private=0):
    """write file to disk with a random name (to compare)"""
    job_no = ""
    if frappe.form_dict.get('folder'):
        path_list = frappe.form_dict.folder.split('/')
        file_path = get_files_path(*path_list, is_private=is_private)
        job_no = frappe.form_dict.get('jon_no')
        if not job_no:
            if frappe.db.exists("Folder Manage", path_list[0]):
                first_folder = frappe.get_doc("Folder Manage", path_list[0])
                if first_folder.folder_type == "Designer":
                    job_no = path_list[2]
                    job_no = path_list[1]
        # create directory (if not exists)
        file_path = get_files_path(is_private=is_private)
    # write the file
    with open(os.path.join(file_path.encode('utf-8'), fname.encode('utf-8')), 'w+') as f:

    return {
        "file_url": get_files_path(*path_list, is_private=is_private).replace(get_files_path(is_private=is_private),
                                                                              '/files', 1),
        "folder": file_path,
        "job_no": job_no

Problem is

when upload file by socketio
below funcrtion contain only file name.

But when I run server as development mode this time work perfectly, I think this time socketio.js doesn’t work or happend something.

socket.on('upload-accept-slice', (data) => {
		try {
			if (!socket.files[]) {
				socket.files[] = Object.assign({}, files_struct, data);
				socket.files[].data = [];

			//convert the ArrayBuffer to Buffer = new Buffer(new Uint8Array(;
			//save the data

			if (socket.files[].slice * 100000 >= socket.files[].size) {
				// do something with the data
				var fileBuffer = Buffer.concat(socket.files[].data);

				const file_url = path.join((socket.files[].is_private ? 'private' : 'public'),
				const file_path = path.join('sites', get_site_name(socket), file_url);

				fs.writeFile(file_path, fileBuffer, (err) => {
					delete socket.files[];
					if (err) return socket.emit('upload error');
					socket.emit('upload-end', {
						file_url: '/' + file_url
			} else {
				socket.emit('upload-request-slice', {
					currentSlice: socket.files[].slice
		} catch (e) {
			socket.emit('upload-error', {
				error: e.message
1 Like

Have you customized your file upload?

Page full js file

@mainul Very hard for me to debug that!

What does your file manager do? Reason why you must always contribute :wink:

Okey @rmehta
I explained you.
My uncle have a small company they re work for image manipulation like (Reove background, retouching etc.)
So there on only Photo or Image.
there workflow Receive a job from client → download images → distribute to Designer → QC → Upload ->Upload backup.
So there need ensure that folder structure return as like received.
same filename receive lot of times but file not same.

I have some solutions

1. I can solved by prev version of frappe

2. I can change socketio file but now time if I change socktio file then file upload in folder but socket disconnected. Hope if i study then I can solved.

! Important

I’m share this problem in this discussion because In frappe framework we have options to change or edit agrs but socketio doesn’t received our args. :wink:
So I thinks that is not fare for developers.

Thanks you so much @rmehta for your nice response.

1 Like