kbnsln
kbnsln

Reputation: 21

RESTful Webservices with PDF as an input file

Is is possible to exchange PDF file as a input for RESTful webservices and also I would like to send PNG image as a response to it. If we can do it through REST services please provide me the references link to implement it using REST services.

Upvotes: 0

Views: 1289

Answers (2)

Edwin Amoakwa
Edwin Amoakwa

Reputation: 51

I was able to achieve a similar output by converting the file to string/byte[] data and sending it via REST.

My implementation was in Java and the steps used is outline below

  1. Convert the file on disk to byte[] array (apache common-io can convert the file to byte[] in easy step. Try the IOUtils class)
  2. Encoded the byte[] as String (apache common-codec was used for the encoding)
  3. Wrapped the string data in a model class
  4. Converted the model class to json format (GSON was used for the conversion)
  5. Sent the json data over to the server
  6. The server application reversed the process, and the file was available on the server

Upvotes: 1

OkieOth
OkieOth

Reputation: 3704

A rest service isn't the right way for what you want. The input for this kind of services are HTTP request attributes or some kind of pushed data. Maybe it's possible to implement a file upload but it's not typical. For restful services is also common to tell your service how to handle the requested resource via the used request method (GET, POST, PUT, DELETE) The response of rest services is normally some kind of structured text output - for instance json.

All in all rest services seems to me not the way to implement your desired scenario. What about a normal cgi or servlet solution?

Upvotes: 0

Related Questions