Reputation: 21
My service has POST method for uploading image file. I am using multipart/form-data request and access to file from Request.Files of Service class as it is recommended in documentation.
public class ImageManagement: Service
{
public void Post(DetectionImageRequest imageRequest)
{
if (this.Request.Files.Length == 0)
throw HttpError.NotFound("File parameter is missing");
// ...
}
}
My issue here is that it seems that ServiceStack doesn't have any problem to match it with Post method in my ImageManagement class if file is missing from Http request. If DetectionImageRequest part of my Http request is missing ServiceStack would certainly report error on that.
Also, file as parameter of http request is not visible in metadata page so the other users are not aware that file need to uploaded. I added check in Post method if file is uploaded and throw exception if it's not but is seems a bit silly throwing exception if documentation doesn't even mention file as requirement.
Is there any way to make file required parameter? Also, is it possible to document file as parameter in metadata page so the user know that it exists?
Upvotes: 2
Views: 426
Reputation: 143339
HTTP Uploaded Files aren't part of the DTO Service Contract, they're uploaded via multipart/form-data
Content-Type so there's no property you can annotate to make it a required field.
You'd can use the description fields in [Api]
or [Description]
attributes to use a textual description to tell API consumers that the Service accepts a file. I'd also recommend using a naming convention for Services that accept files, e.g. having them start with an Upload*
prefix.
Upvotes: 1