Is it possible to drag a remote file out of Electron App onto the file system?

偶尔善良 提交于 2019-12-05 03:36:29

问题


I have been playing around with the file system drag and drop functionality of Electron apps and haven't had any issues getting everything to work with local files. I have not come across anything in the documentation, so I'd like to see if anyone knows if this is possible. I'd like to use the drag-out feature in Electron to drag a remote file outside of the app and onto the file system.

Specific example: The program I am working on is a remote file management tool - similar to dropbox. I'd like to drag the dom element representing the remote file to a Finder (or Windows Explorer) window and have Electron download the file to that location.

I am able to get this to work as long as the file is stored locally following the Electron documentation. http://electron.atom.io/docs/all/#dragging-files-out-of-the-window

I can envision two possible solutions:

  • Does electron have the ability to pass a DownloadItem or a URL to the 'startDrag' event (as referenced in the link above)?
  • Is it possible to listen for a 'dropped' even of some kind and get the local file system path of where my dom element was dropped? For example, /Users/{proile}/Desktop? I could use my existing download methods to download the file to that specific path.

Any thoughts on how I can accomplish my goal? Thanks so much for your time.


回答1:


I haven't seen any examples of this sort of functionality – but it doesn't seem like it would be hard to cobble it together (famous last words...)

  1. You have your representations in the UI of the remote files and those are enabled to be "dragged" to the desktop.
  2. You catch the target destination when the user drags one of those representations
  3. You start a download of the associated file and save it to the target destination

At least that is how I would start to approach it. There are various electron related libs dealing with downloads (e.g. electron-dl). If you get this working, report back and share the details.



来源:https://stackoverflow.com/questions/43209509/is-it-possible-to-drag-a-remote-file-out-of-electron-app-onto-the-file-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!