filemanager icon indicating copy to clipboard operation
filemanager copied to clipboard

Upload error in electron application

Open aquinovo opened this issue 6 years ago • 9 comments
trafficstars

It works correctly in the web application. But when run or build the executable with electron I can no longer upload files.

TypeError: source.on is not a function at Function../node_modules/delayed-stream/lib/delayed_stream.js.DelayedStream.create (delayed_stream.js:33) at FormData../node_modules/combined-stream/lib/combined_stream.js.CombinedStream.append (combined_stream.js:44) at FormData../node_modules/form-data/lib/form_data.js.FormData.append (form_data.js:74) at Request../node_modules/superagent/lib/node/index.js.Request.attach (index.js:204) at Object._callee9$ (api.js:327) at tryCatch (runtime.js:62) at Generator.invoke [as _invoke] (runtime.js:296) at Generator.prototype.(anonymous function) [as next] (file:///home/aquino/Documentos/Datyra/Proyectos/monitor-editor/build/bundle.js:137601:21) at step (asyncToGenerator.js:17) at asyncToGenerator.js:35

uploaderror

aquinovo avatar Jan 23 '19 03:01 aquinovo

Hi @aquinovo!

Sorry, but I can't determine the reason of issue which I can't reproduce.

Sure I'll can help if you'll provide me a git repo where I can npm start to debug.

kvolkovich-sc avatar Jan 23 '19 08:01 kvolkovich-sc

@kvolkovich-sc https://github.com/aquinovo/filemanager this is my repo.

aquinovo avatar Jan 24 '19 16:01 aquinovo

Good. I'll take a look today.

kvolkovich-sc avatar Jan 25 '19 08:01 kvolkovich-sc

Spent about two hours with no positive result.

I also noticed random errors after folder creating/renaming.

And wrong refresh directory behavior.

...strange errors about GTK (I'm on Linux) in terminal when I try to upload/rename something.

I suggest you try to find out the bug by yourself.

I'm not closely familiar with Electron, but I'll try tomorrow again. Not sure that I can spend a lot of time on it.

kvolkovich-sc avatar Jan 25 '19 23:01 kvolkovich-sc

@kvolkovich-sc Thank you very much. I will keep trying.

aquinovo avatar Jan 25 '19 23:01 aquinovo

I don't think that could be the reason, but I think it's worth taking a look at this:

I saw that in /utils/upload.js the dom input element is being deleted just after click(). I noticed that in Chrome sometimes the files were not being upload after selected. I solved that by moving the document.body.removeChild(uploadInput); after the resolve bit.

All browsers have a different way to handle the dom and Electron may not like the fact that the input element is not there anymore? 🤷‍♂️Just a guess

Good luck

From:

    uploadInput.addEventListener('change', _ => {
      const file = uploadInput.files[0];
      resolve({
        type: file.type,
        name: file.name,
        file
      });
    });

    // This input element in IE11 becomes visible after it is added on the page
    // Hide an input element
    uploadInput.style.visibility = 'hidden';

    uploadInput.type = "file";
    document.body.appendChild(uploadInput);
    uploadInput.click();
    document.body.removeChild(uploadInput);
  });
}

export {
  readLocalFile
}

To:

    uploadInput.addEventListener('change', _ => {
      const file = uploadInput.files[0];
      resolve({
        type: file.type,
        name: file.name,
        file
      });

      document.body.removeChild(uploadInput);
    });

    // This input element in IE11 becomes visible after it is added on the page
    // Hide an input element
    uploadInput.style.visibility = 'hidden';

    uploadInput.type = "file";
    document.body.appendChild(uploadInput);
    uploadInput.click();
  });
}

export {
  readLocalFile
}

bichotll avatar Feb 26 '19 10:02 bichotll

@kvolkovich-sc I can create a PR for that btw if you are happy with that proposal. I think that my proposed logic is "more correct" than the previous one as we are getting rid of the element once the operation is completed.

bichotll avatar Feb 26 '19 10:02 bichotll

There was a small issue there. The input would not be deleted if a file was not selected.

This fixes that: http://jsfiddle.net/Shiboe/yuK3r/6/

bichotll avatar Feb 26 '19 12:02 bichotll

@bichotll PRs are welcome!

kvolkovich-sc avatar Feb 26 '19 17:02 kvolkovich-sc