Is it possible to drag a remote file out of Electr

2019-03-31 18:43发布

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条回答
Ridiculous、
2楼-- · 2019-03-31 18:54

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.

查看更多
登录 后发表回答