Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to get the files from DataTransfer (from DragEventArgs.DataTransfer)? #62981

Unanswered
datvm asked this question in Q&A
Discussion options

It's strange to me that DataTransfer.Files is a string[] and there is no reference (that I am aware of) to grab the content of it.

How do I get the file data from an ondrop event?

 void OnDrop(DragEventArgs e)
 {
 dragClass = "";
 if (Disabled) { return; }
 var files = e.DataTransfer.Items;
 if (files.Length == 0) { return; }
 // What now?
 }

Is it by-design? Is there even access to an IJSObjectReference so I can grab it with Javascript?

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Hello @datvm,
in Blazor, DataTransfer.Files only gives you file names, the actual file objects stay in the browser. This is by design to avoid automatically streaming large files over the JS/.NET boundary.
If you need the content from an ondrop event, you have to use JS interop to read dataTransfer.files and then send the data back to .NET.
You can’t get the bytes directly from DragEventArgs alone.

You must be logged in to vote
1 reply
Comment options

Thanks for confirming. I had to make it work so like you said I just use Javascript interop for the whole thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /