Vaadin Flow:如何使用拖动的文件
我有一个部分(DropTarget),用户可以在其中从我的应用程序中删除多个项目。 这很好用。
现在我还想允许用户将文件拖到该 DropTarget。
当我将文件拖动到 DropTarget 时,我注册的放置侦听器会收到通知,但是 - 据我所知 - 不提供任何使用拖动的文件的可能性。
有人知道如何让它运行吗?
使用 Vaadin 流 22.0.7
I have a section (DropTarget) where the user can drop several items from within my application.
This works fine.
Now I would also like to allow the user to drag files to that DropTarget.
The drop listener that I registered gets notified when I drag a file to the DropTarget, but - as far as I see - does not offer any possibility to consume the dragged file.
Anybody knows how to get this running?
Using Vaadin flow 22.0.7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建上传组件时,您可以指定一个
接收器
。您可以将其作为构造函数参数或通过upload.setReceiver(Receiver)
传递。根据您的使用情况,有不同类型的接收器;如果您同意将所有数据放入服务器内存中,则可以使用MemoryBuffer
,但还有其他选项,例如FileBuffer
,如下所示:< a href="https://vaadin.com/docs/latest/ds/components/upload/#handling-uploaded-files-java-only" rel="nofollow noreferrer">https://vaadin.com/docs/latest/ds/components/upload/#handling-uploaded-files-java-only ;您也可以实现自己的Receiver
。Receiver
使您可以访问文件的实际流内容。通常,您希望在上传过程的某个阶段访问数据,这可以通过不同的上传侦听器来完成。如果您只想在上传完全完成后处理它,则可以使用SucceededListener
:实现您自己的
Receiver
可以让您更灵活地处理如何处理来自上传的OutputStream
,当然你可能不想将上传保存为物理文件,而是直接将其放入数据库中。When you create an Upload component, you can specify a
Receiver
. You can pass one as a constructor parameter or viaupload.setReceiver(Receiver)
. There are different types of Receivers depending on your use case; you can use aMemoryBuffer
if you are ok with putting all of the data in your server memory, but there are other options, likeFileBuffer
, as can be seen here: https://vaadin.com/docs/latest/ds/components/upload/#handling-uploaded-files-java-only ; you can implement your ownReceiver
as well.The
Receiver
gives you access to the actual streaming content of the file. Typically, you want to access the data in some stage of the upload process, which you can do through different upload listeners. If you just want to deal with it once the upload is fully complete, you can use aSucceededListener
:Implementing your own
Receiver
gives you more flexibility on how you want to handle theOutputStream
from the upload, and of course you might not want to save the upload as a physical file, but put it directly in a database for example.