Setting file size restrictions when uploading files with Jersey

后端 未结 5 1850
孤独总比滥情好
孤独总比滥情好 2021-01-04 08:42

I\'m currently implementing functionality for uploading files using jersey rest. I would like to set a maximum allowed file size which to me seems like a pretty common requi

5条回答
  •  日久生厌
    2021-01-04 09:02

    If the client does not send the file size, fall back to reading the file from stream. Once you hit the size limit, stop reading and refuse the file. You should do this anyway, since you can't trust the client (anyone can create an app that sends http requests to your service and those requests may not have correct data you expect - so have to take that into account).

    In addition, it may be possible to add some validation to the web form as well to fail fast, but I am not a JavaScript expert, so not sure if/how that can be done.

提交回复
热议问题