是否可以将远程文件从 Electron App 拖到文件系统上?

2023-01-28前端开发问题
32

本文介绍了是否可以将远程文件从 Electron App 拖到文件系统上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我一直在尝试使用 Electron 应用程序的文件系统拖放功能,并且没有遇到任何问题,可以让所有内容都与本地文件一起使用.我在文档中没有遇到任何内容,所以我想看看是否有人知道这是否可能.我想使用 Electron 中的拖出功能将远程文件拖出应用程序并拖到文件系统上.

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.

具体例子:我正在开发的程序是一个远程文件管理工具——类似于 Dropbox.我想将代表远程文件的 dom 元素拖到 Finder(或 Windows 资源管理器)窗口,并让 Electron 将文件下载到该位置.

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.

只要文件按照 Electron 文档存储在本地,我就可以让它工作.http://electron.atom.io/docs/全部/#dragging-files-out-of-the-window

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:

  • electron 是否能够将 DownloadItem 或 URL 传递给startDrag"事件(如上面链接中所引用的)?
  • 是否有可能监听某种丢弃"并获取我的 dom 元素被丢弃的本地文件系统路径?例如,/Users/{proile}/Desktop?我可以使用我现有的下载方法将文件下载到该特定路径.

关于如何实现我的目标有什么想法吗?非常感谢您的宝贵时间.

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

推荐答案

我还没有看到任何此类功能的示例——但看起来并不难拼凑起来(著名的遗言...)

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. 您在远程文件的 UI 中拥有您的表示,并且可以将这些表示拖动"到桌面.
  2. 当用户拖动其中一种表示时,您会捕捉到目标目的地
  3. 您开始下载相关文件并将其保存到目标位置

至少我会这样开始处理它.有各种与电子相关的库处理下载(例如 electron-dl).如果你得到这个工作,报告回来并分享详细信息.

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.

这篇关于是否可以将远程文件从 Electron App 拖到文件系统上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437

layui中table列表 增加属性 edit="date",不生效怎么办?
如果你想在 layui 的 table 列表中增加 edit=date 属性但不生效,可能是以下问题导致的: 1. 缺少日期组件的初始化 如果想在表格中使用日期组件,需要在页面中引入 layui 的日期组件,并初始化: script type="text/javascript" src="/layui/layui.js"/scrip...
2024-06-11 前端开发问题
455

Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)...
2024-04-20 前端开发问题
5