Can I upload a file through the GWT RPC servlets?

Can I create a file upload using the GWT RPC Googles engine? Since now I am using a simple HTTPServlet with the doPost method, which gets the address from the form!

Is it possible (without the help of libraries such as gwtupload) to upload an XML file via GWTs FileUpload Widget to the RPC service and work with the contents of the file?

BR; mybecks

+4
source share
2 answers

There are actually two ways to download a file from gwtupload, as you mentioned, and through gwt-rpc this is a bit complicated due to browser security. To implement with gwt-rpc, you must override the service(final HttpServletRequest request,HttpServletResponse response) method service(final HttpServletRequest request,HttpServletResponse response) inside your service implementation that inherits RemoteServiceServlet . On the client side, you should have code like this:

 final FormPanel formPanel = new FormPanel(); formPanel.setAction(GWT.getModuleBaseURL()+"fileUpload"); formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); 

Inside the service you can get the file using FileUpload and don't forget to register the file url template in your web.xml as well as @RemoteServiceRelativePath("path") in your service interface, which inherits RemoteService . Good luck

+5
source

Perhaps, but it is not so simple. First you will need to read the file from the client code. Most browsers support the FileReader API, but not all of them. Thus, for Internet Explorer you will have to use flash memory or another plugin to access files.

In addition, by default in GWT there is no binding to the file reading API, so you have to do it yourself.

The next thing you are going to send Base64 encoded files through GWT-RPC, and you have to decode on the server side. Because of this, you may encounter some memory problems if your users start downloading a large number of large files (about 20 mb).

+3
source

Source: https://habr.com/ru/post/1395011/


All Articles