1

I want to implement a ServiceStack endpoint enabling user to upload an icon. I have two questions:

  1. Where should I put the image in the request? Currently I use a Firefox extension called HttpRequester and add my image as a file in contents part.
  2. Where should I look for the content in the request? According to some other posts, request.Files should have it but it is empty.
Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83
Mahdi
  • 3,199
  • 2
  • 25
  • 35
  • 2
    `Request.Files` should work if the client is sending `multipart/form-data`. Also, check out [this SO question](http://stackoverflow.com/questions/16475720/using-servicestack-to-upload-image-files) – PatrickSteele Mar 02 '16 at 16:48

1 Answers1

2

This is the working code (ServiceStack 4).

Model:

[Route("/api/upload", Verbs = "POST")]
public class UploadRequest: IReturn<UploadResponse>
{
     public byte[] Data { get; set; }
}

public class UploadResponse
{
    public ResponseStatus Response { get; set; }
}

Service:

public UploadResponse Post(UploadRequest request)
{
    Request.Files.ForEach(f => ProcessFile(f));
    return null;
}

private void ProcessFile(IHttpFile file)
{
     // logic here
}
Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83
  • I now think that this `Date` property is not needed. The issue might indeed be with wrong format type. There is an example on the SS customer forum: https://forums.servicestack.net/t/how-to-upload-a-file-and-post-json-data-in-the-same-request/3318 – Alexey Zimarev Jun 15 '17 at 19:42