It is possible to PutFilesWithRequest? #23
-
I am building a PUT endpoint which takes fields as well as files. However, I see there is no 'PostFilesWithRequest' variant for PUT methods. Is there anyway around this? I want to test my fluent validation for files in this endpoint, but am unable due to not being able to upload a file. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
The vast majority of HTTP File Uploads with additional Request params are done with POST so we don't want to duplicate the API surface area to support an unused method. You can override and Simulate alternative HTTP Methods in ServiceStack with the var client = new JsonServiceClient(baseUrl) {
RequestFilter = req => req.Headers[HttpHeaders.XHttpMethodOverride] = HttpMethods.Put
}; Alternatively you can use the using var uploadRequest = new MultipartFormDataContent()
.AddParams(new MyRequest {
//...
})
.AddFile(fieldName, fileName, fileStream);
var api = await client.SendFormAsync<MyRequestResponse>(HttpMethods.Put, typeof(MyRequest).ToApiUrl(), uploadRequest); |
Beta Was this translation helpful? Give feedback.
-
Yeah it should override the HTTP Method, can you provide the raw Request/Response headers (i.e. w/o request body). You can use a HTTP sniffer like Fiddler or Wireshark. |
Beta Was this translation helpful? Give feedback.
-
I've added a change that changes the PostFilesWithRequest APIs to use its preferred HTTP Method if one exists, e.g. if you only have a single route with a single verb it will use PUT otherwise you'll need to add the This change is available from v6.1.1+ that's now available on MyGet. |
Beta Was this translation helpful? Give feedback.
I've added a change that changes the PostFilesWithRequest APIs to use its preferred HTTP Method if one exists, e.g. if you only have a single route with a single verb it will use PUT otherwise you'll need to add the
IPost
marker interface to your Request DTO.This change is available from v6.1.1+ that's now available on MyGet.