Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File Picker Possible in a Web Service?  RSS feed

 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple REST Web Service (spark java) and I'm trying to augment a third-party application that no longer has a native file picker.

The problem is that the Swing file picker expects a reference to an object on the Swing form.

So, from that third party application, I want to call the web service method via a GET, (somehow) present a file picker dialog in the web service, when called via a GET method, (if possible) and return the result.

What's a good approach here?

Can Java do this? No way I can think of to use JFileChooser here.

Thanks in advance,

- mike
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File picker inside web service? The whole idea doesn't make sense!

A web service API is for someone to call. The parameters to this API can be anything.

If say you pass in a file picker object into it (part of the request) ... why not pass in the file name instead or the Base64 binary hex (not recommend really)

Similar token, what is returned? A file? If so the Base64 binary hex is feasible here.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:File picker inside web service? The whole idea doesn't make sense!

A web service API is for someone to call. The parameters to this API can be anything.

If say you pass in a file picker object into it (part of the request) ... why not pass in the file name instead or the Base64 binary hex (not recommend really)

Similar token, what is returned? A file? If so the Base64 binary hex is feasible here.


The idea is that some programs can't display a dialog picker, but they can do a GET.

My REST service now just instantiates an AWT File Dialog (JFileChooser hung after a single display) and returns the file name back to the third party program.

Thanks,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again that makes no sense -- REST APIs do not have UI. Of what use is a UI on the server? How is the client program supposed to interact with it?
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Again that makes no sense -- REST APIs do not have UI. Of what use is a UI on the server? How is the client program supposed to interact with it?
'

It may not "make sense", but it works. If you have a better way to show a file picker dialog, using Java, to a program that has no file picker dialog, I'd LOVE to hear it!

--------------------------
Here's how it works:
--------------------------
Client program calls WS via GET

WS instantiates file dialog

User picks file

File dialog returns the file to the WS

WS returns the file name (path) to the client program.

---

Again, I would like to hear your thoughts that "make sense" about how you would implement a file picker for this situation.

Thanks Bear.

- mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file picker should be in the client program.

You are testing the client and server co-located, yes?

What happens when the client is running in Sacramento, and the server is in New York? Is the Sacramento user expected to fly to New York to pick the file?
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike from what you described, your WS purpose is to get the list of files for the user/client to choose from in a file picker. This file picker belongs to the client program.

Once the user choose the file, another WS call to actually get the content of that file.

If this is how it supposed to work, where those files are shouldn't be a problem. As long as the WS has access to them.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The file picker should be in the client program.

You are testing the client and server co-located, yes?

What happens when the client is running in Sacramento, and the server is in New York? Is the Sacramento user expected to fly to New York to pick the file?


Yes, the service and files must be on the same box. The WS is just an extension of the client so they have to be co-located or it, I agree, wouldn't make sense.

Thanks,

-- mike
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Mike from what you described, your WS purpose is to get the list of files for the user/client to choose from in a file picker. This file picker belongs to the client program.

Once the user choose the file, another WS call to actually get the content of that file.

If this is how it supposed to work, where those files are shouldn't be a problem. As long as the WS has access to them.


The WS + File Dialog just returns the path to the file not the content. The client application can access files once it has the path.

Thanks for posting back.

- mike
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!