New answers tagged

1

Checking the file suffix seems easy, but ultimately pointless. A file named foo.bar might be a valid jpeg file. A file named reallyIsA.jpg might be a nasty virus. Remember when some corporate firewalls forbid you from emailing .exe or .zip files and everybody just changed the extensions? IMO, your API should specify "a file in one of these image formats: ...


1

You should provide an API with documentation. In your documentation you should document what unusal inputs are handled well, what incorrect inputs you will detect and how you will respond to them - and what incorrect inputs you will not detect. And your implementation should follow that documentation. Your API can be written with the attitude "calling it ...


0

In this example and in most other real world examples the overhead of validation will be negligible compared to the work your API is supposed to do. For starters you may want to create a class MediaFile that encapsulates the input of your API. All validation can then be done in the constructor of the media file class. MediaFile could be abstract and you ...



Top 50 recent answers are included