0

how to get name of uploaded file [closed]

asked 2018-05-11 01:14:54 +0800

jgomer2001 gravatar image jgomer2001
1

Hi, I am successfully doing file uploads:

<button label="..." upload="true,maxsize=10240,multiple=false" onUpload="@command('uploaded', uplEvent = event)" />

I want to know if I can get the name of the file the user chose. Currently I can read the raw contents (bytes) at my viewmodel: @Command public void uploaded(@BindingParam("uplEvent") UploadEvent evt) { ...

I would like to have a String with something like my_image.png or whatever the selection was made by the user.

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by cor3000
close date 2018-05-21 14:41:24

Comments

great, it works. I was doing event.getName() :(

jgomer2001 ( 2018-05-14 22:29:54 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-05-14 16:26:26 +0800

cor3000 gravatar image cor3000
4089 1 7
ZK Team

you can get the file name via:

UploadEvent#getMedia()) -> Media#getName())

in your case: evt.getMedia().getName() should give the desired result

In MVVM I tend not to add the raw event object into my ViewModel and do this instead:

<button label="..." upload="true,maxsize=10240,multiple=false"
        onUpload="@command('handleUpload', media = event.media)" />

@Command 
public void handleUpload(@BindingParam("media") Media media) {
    System.out.println(media.getName());
}
link publish delete flag offensive edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2018-05-11 01:14:54 +0800

Seen: 6 times

Last updated: May 14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More