I am looking for a solution to upload a file from a client to a server connected through a web service.
The client is written in c# and the web Service in java.
The files can be rather large < 100MB.
What approach would you suggest is best ?
Base64 encode the file and send it as an attachment. If you need to make sure the contents of the attachment do not get changed en route, use MTOM. Otherwise, use DIME.
Agree an encoding on both client and server then serialize the file using that encoding, wrap it in CDATA tags and assign the value to a text node in your SOAP request on the client.
Read the data between the CDATA tags on the server, deserialize it using the agreed encoding and you'll have the byte stream to use as need be.
It's probably a good idea for the encoding to involve some sort of compression if the files are large, although be wary of interop issues if the client is .NET and the server Java.
For the server side, you should have a look at Commons File Upload
Related
We need to upload and process XML files. I convert them to bytearray and send through Websphere MQ/Spring JMS and process the file in the backend application server. The Websphere MQ has a message size limit of 2MB. We don't have control over that. Please recommend an efficient way to split the file/bytearray and have them assembled/merged in the datazone.
Is it easy to split the XML and pass chunks of XML data as bytearray. Examples/sample code would be fantastic. Please advise. Thanks
https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q026360_.htm
You should be able to use the flag MQMF_SEGMENTATION_ALLOWED and MQGMO_COMPLETE_MSG which lets the MQ API split and reassemble large messages.
However, it's not supported by all platforms, in which case you have to do that programmatically using the the GroupId,MsgSeqNumber,Offset and OriginalLength MQMD fields.
I have in my disposal a Spring MVC backed server, using AngularJS in client side to display dynamic content. Was researching possibility to get current content displayed in the browser and convert it to a word document.
I assume there's a way to do build word documents with Java, but to do so i'll have to send existing HTML to the server side - how would i do that? just send the document DOM object?
Suppose i'll be able to do so, what if i want to include 2 images? I do know its possible to send images as base64 string.
To conclude, my general approach would be to try and send all client side data to the server and use Java to generate word document.
I have found docx4j so this approach seems possible.
Is that the right way to go? Any thoughts would be appriciated.
On the server side, you can use a library like Apache POI for creating docx documents.
There are multiple ways to pass data from client to server:
Make an AJAX call
How to send FormData objects with Ajax-requests in jQuery?
Ajax Upload image
Submit a form from the client side to the server using POST. Using multi-part forms will allow you to send attachments to the server
See Handling HTML (multipart form-data) file uploads with Java
On the client side, there are some JS libraries available for creating docx documents:
https://github.com/evidenceprime/html-docx-js
Generate a Word document in JavaScript with Docx.js ?
I have a web app that within it, it gets a base64 from the client side, omitting the details here is how the base64 is retrieved:
String source = e.getAttribute("src");
String base64 = source.substring(source.indexOf("base64,") + 7)
Now that the base64 string is retrieved, I need to upload it via Form upload. I'm not sure what is the correct approach to upload this as a File to my working backend.
The problem is not the backend, I have tested it to receive standard Form upload and it works fine. So the issue I face, is how to upload the base64 say to a backend endpoint /blob/upload
Update:
I'm thinking of using GWT Rpc to upload the base64 String but I am not sure if that is efficient for large files.
Is there a particular reason you're uploading a Base64 String? It will probably get messy.
If there is no reason to do it that way, use the com.google.gwt.user.client.ui.FileUpload widget on the client, and make a simple HttpServlet on the backend to accept the files.
You can then use the Apache Commons FileUpload library to grab the uploaded files and do with them as you please (See "The Simplest Case" section of that page for usage details. It's pretty easy to use).
Also, beware of large files. The default Tomcat POST size is 2 megabytes, I believe.
This is going to be running on a server which will then send the xml request to another server (over which I have no control). I can't afford to write an xml to the hard drive for every request. So ideally I'd like to create an xml without creating the file.
This shows how to send an xml file (not an object) over https: http://pic.dhe.ibm.com/infocenter/iisinfsv/v9r1/index.jsp?topic=%2Fcom.ibm.swg.im.iis.ia.restapi.doc%2Ftopics%2Fr_restapi_sending_https_java.html I've got that part working, problem is even after changing the content type to xml I think it was simply sending the content of the xml as plain text which seems very inelegant.
I'd rather avoid third party jars as much as possible but I do have access to the apache.axiom and axis 2 library.
So long story short: how do I make an xml object and then send it via HTTPS to a third party web-service that is not using SOAP or REST.
The HTTP request is generally correct to send XML as text, with the correct content type.
If you have a DOM object of some sort, you would just serialize it to XML, as text, either on disk or in a buffer or a string, and then send that, as per the link, to the other server. The other server will parse the XML string and get whatever form of object it wants.
I dont have any experience for web services. please give me some suggestion about the task below.
the task is:
users will send a txt file (size should less than 20K ) from a .NET application, I need to write a web services which runs by jboss 5.x to read this file and edit this file and send the file back to .NET UI to display the edited version.
question is that if the txt file is just text string or binary string, are there any restriction of the string length? if it's binary string, can I need to use BinaryReader class to read it? or not need special reader to read it? (this could be a dumn question :P)
what if the .NET application can save the file on either the .NET application server or some shared server location, send a download URL to web serivces, can web services download it and read it? JBoss will be run on Linux sever.
After edit the file, how do I send it back?
Thanks for your help!
It's hard to find reliable information about limitations in size, this depends on the libraries you use.
I would rather use an attachment than a single string containing the whole file Handling attachments in SOAP
For .Net see Add Attachments to a SOAP Message by Using DIME
After edit the file, how do I send it
back?
Request processFile(File)
Response UniqueId
Request getProcessedFile(UniqueId)
Response Edited File