0

I've got an application which is using a REST Web-Service to synchronize the data with other people. Till now the data are just text-based so I use XML files to store the data on a database and load it on the clients.

But now I want to extend this application to add images and snyc them on the Web-Service. I'm not sure what is the best practice this use case.

1) Saving the images at the database

2) Saving it on the file system and add a link in the database to the path

so what would you do and why?

And I need an example for store/load images to/from Jersey REST Web-Service from a Java client. :)

рüффп
  • 5,172
  • 34
  • 67
  • 113
Birdy
  • 355
  • 1
  • 5
  • 15
  • A previous post talks about this http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay – AurA Jun 19 '13 at 14:35
  • *Hi I'm posting a dup question... And I need an example for store/load images to/from Jersy REST webservice from a java client.* Do you also want us to prepare a cup of coffee and give you cookies while you wait for your answer? – Luiggi Mendoza Jun 19 '13 at 14:37

1 Answers1

2

There are some directions but not the complete code to spoon feed you. Hope you use these tips to develop the REST service by yourself.

  1. You need to develop a service to accept multipart data in request. It can be either multipart/form or mulitpart/mixed depending on your choice.

  2. You can save the file on a disk and can store the path and other details of it in the database for retrieval later on. You may need file details for requests such as GET/PUT/DELETE.

  3. You may want in the request to get the actual file stream and some details about the file like name, etc. So you may have to create a file details class for that.

Here is a sample method contract for such a service:

/**
 * 
 * @param imageFileInputStream actual file stream
 * @param imageUploadConfig image details
 * @return Response
 */ 

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadImageFile(@FormDataParam("imageUploadConfig") String strImageUploadConfig,
        @FormDataParam("imagefile") InputStream imageFileInputStream);
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136