0

I need to compose a spring controller (server side of course) for uploading files - when I get the file I need to run some validations. The thing is - my clients may try to upload some really big file and I would like to run this validation based on a meta data they will supply.

What is the best practice for this? What should be the resource they should run the validation against?

For example, the file resource may seem like this:

POST .../files
GET .../files/{id} or ../files to get all
DELETE ../files/{id}

Of course the validation will be in each method - but as I said before, I would like to enable the client to run the validation in a decoupled manner.

Thanks

Noam
  • 3,049
  • 10
  • 34
  • 52
  • What kind of meta data? If it's information that is passed as part of the http request (ie set in the header), you can query the `HttpServletRequest` before handling the file uploads. – IllegalArgumentException Oct 08 '17 at 11:18
  • @breezee - the meta-data is passed as part of the file (it's a zip file which contains the meta-data itself) – Noam Oct 08 '17 at 11:22
  • See https://stackoverflow.com/a/11016610/1176462, create a POST request mapping, get the request's input stream as `ZipInputStream` where you can read the zip file by entries and if you know what the metadata file is, read and validate it first (by query the `ZipEntry`'s). – IllegalArgumentException Oct 08 '17 at 11:30
  • @breezee - Thanks for your response - but I think that in order to use it - I will need all the file to be uploaded (as I said, the validation is done in the server's side). Am I right? – Noam Oct 08 '17 at 11:35
  • No, getting an `InputStream` reference doesn't mean you read it yet. You can choose how and if to read it, server-side. – IllegalArgumentException Oct 08 '17 at 11:51
  • @breezee - OK - I will test that. – Noam Oct 08 '17 at 12:34
  • @breezee - I couldn't find a way to implement this - composed this new question - https://stackoverflow.com/questions/46717066/how-to-run-validation-on-an-uploaded-file-before-uploading-it-all-in-java – Noam Oct 12 '17 at 19:01

0 Answers0