A common requirement for web applications is to enable users to upload files to a server. In this recipe, we will build a service to handle file uploads and give an example of it working with both a web client and a .NET client.
If you are starting with a new project, please go to section Creating a ServiceStack solution with Visual Studio and NuGet, Appendix A, Getting Started, to help you get set up.
Create the request object for the file upload service, as follows:
[Route("/fileupload/simple")] public class SimpleFileUploadRequest { public string FileName { get; set; } public string UploadedByUserName { get; set; } }
Create the service to handle the file upload, as follows:
public object Post(SimpleFileUploadRequest request) { if (Request.Files.Length == 0) { throw new HttpError(HttpStatusCode.BadRequest, "NoFile"); } string resultFile = @"../../" + Request.Files[0].FileName; Request.Files[0...