• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Web Service to upload files (using Multipart files)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have to write a Java wrapper for the following REST web service:

Request URL: https://myServer:8080/myDomain/rest/myProject/run/555/log-attachment
Method: POST
Request Header:
[Accept: application/xml]
[Content-Type: multipart/form-data; boundary=XXXXXXX]

I was unclear on how and where the file boundry value would come from, that needs to be passed in to the request as a header.
Would anyone know this?

In regards to the multipart file parameter, I was a bit unclear on how the implementation would go. Would any one have any sample code for this?

This example was not too clear as it uses deprecated APIs:
https://discursive.atlassian.net/wiki/display/CJCOOK/Uploading+Files+with+a+Multipart+POST

Any good references/examples to multipart file uploads using Java would be greatly appreciated!

Thanks,
Sheeraz
 
Ranch Hand
Posts: 171
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly are you implementing?? A wrapper class which will lie on server?? Or client of the service available on the server??

If it is wrapper on the server which will be deployed on server only then you don't have to bother about the boundary at all, it would be sent to you by client.

If you are writing a client, then you need to understand what exactly a boundary is-
Boundary is a pattern (a pattern made of different characters, don't get confused with design pattern here) which is used as terminator for multiple parts of a request, & is assumed that the parts of request will never contain that pattern. You can have your own pattern (which can even differ for every request), just make sure that it never appears inside your file. you can use ones generated by any browser or modify them as per your interest and/or need.
 
Sheeraz Memon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anurag for the response. The implementation is for the client of the service. I understand the concept of the boundary, and that it acts more like a delimiter. However, would you know of the exact steps of how to get the boundary from the browser (or how to generate a boundary)?? I could not find any example (set of steps) that has this info.

Thanks again for your time on this.
-Sheeraz
 
Anurag Verma
Ranch Hand
Posts: 171
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can write a test servlet which prints all the headers on console for every request received & can have a sample html page having one form with one file upload input & a submit button, action of the form should be targetting to this servlet. upload the file, have all contents on the console.
Second way is ....have (or find) a web page where a file upload control exists. start tracking it with HttpFox plugin of firefox (no ad intended), upload a file & see the request headers. Copy your boundary value from there.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic