Retrive base64-file from multipart/form-data POST request [duplicate] - java

This question already has answers here:
How can I upload files to a server using JSP/Servlet?
(14 answers)
Closed 6 years ago.
I receive a request (multipart/form-data POST), parameter "file" contains file as a base64 (example below)
------WebKitFormBoundaryEA37wQGzpnprPt8x\r\nContent-Disposition: form-data;
name=\"file\"\r\n\r\nJVBERi0xLjQNJeLjz9MNCjEgMCBvYmoNPDwvQXV0aG9yIChNYXJrbyBLZWpcMjM2YXIpL0Ny\r\nZWF0aW9uRGF0ZSAoRDoyMDE2MTEyMjExMzc0NCswMScwMCcpL0NyZWF0b3IgKE1TIFdvcmQg\r\nRG9jdW1lbnQ
I am curious how to decode it (using JAVA of course) from there and get a file.
Should I somehow delete system information (WebKitFormBoundary and Content-Disposition)?
I also noticed that content full of \r\n Do I need to delete it myself as well?

you can use following link to decode from base64
https://www.base64decode.org/

Related

simulate curl -d request in HTTP [duplicate]

This question already has answers here:
Sending HTTP POST Request In Java
(12 answers)
Convert Curl to Java equivalent
(1 answer)
Closed 5 years ago.
I want to simulate a request of the form curl -d "param = value" "http://ip:port?key1=value1&key2=value2" using the REST API Testing, but unfortunately I do not know how. More details about the -d flag can be found here.
If I use POST for the method type then I get a 405 error and if I use GET for the method type then I get a 404 error. From the command line the command works perfectly and I am able to receive the answer, but I do not know how to adjust the snippet -d "param = value" in a HTTP request.
I really appreciate any kind of help !!!

Getting 400 bad Request with Tomcat 8.5.9 [duplicate]

This question already has answers here:
How to pass a JSON array as a parameter in URL
(9 answers)
Closed 5 years ago.
I'm new to tomcat server technology. Currently I'm working on the spring boot application and I tried calling the below api with the tomcat servers (below 8.5v) running in the background, I got the response as I expected. But when I tried to call the same api with tomcat server 8.5.9v running in the background I'm getting the 400 bad request.
http://localhost:8080/TestRest/ExtractTest?jsonString={"extract":
{"Type":"veswanth", "objects":[{"object":"WTT"}]}}
And in the log file I found the below issue
service Error parsing HTTP request header Note: further occurrences of
HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the
request target. The valid characters are defined in RFC 7230 and RFC
3986
Kindly help me to fix this issue and correct me if did anything wrong..
You can not pass json data in url in that way. You need to pass it in body and request method should be POST.
You can refer this:
How to pass a JSON array as a parameter in URL

Upload CSV file to servlet then pass it to java program [duplicate]

This question already has answers here:
How can I upload files to a server using JSP/Servlet?
(14 answers)
Closed 9 years ago.
I have written a stand along java program that loads a CSV file with addresses line by line and geocodes them using an API. I have now been given the task of making this program run off a server. I have no experience dealing with servers. Basically what I need to do is the following,
1. Upload the CSV file to the server via a servlet
2. Pass in the file location as a String parameter into my java code via a function call.
Any help would be much appreciated. Thank you.
You basically need to write a servlet to handle a POST request to upload the file. The message body of POST can be of multipart/form type to contain both the path of the file and actualy bytes of the file. Just extract this information from the incoming request in servlet and do the processing as you need.
You may explore Apache Commons Fileupload for doing the same.

how to send HTTP request to a servlet [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to send HTTP request in java?
I only have one servlet running on the Tomcat server side. Now I want to send a HTTP request to this servlet from a Swing application, and it's not an APPLET application (because I see some examples sending request from applet). How can I do this?
While you can open a direct socket connection and send the raw HTTP headers & content and receive a response back, I would urge you to take a look at HttpRequestBase.

How to do a POST inside a JSP or Servlet? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use java.net.URLConnection to fire and handle HTTP requests?
I need to do a http post call to an external URL from my servlet. And I need to add some custom http headers too to the message. Is this possible ? please provide me a guidance.
You can try apache HttpClient library.

Categories