Chris
Chris

Reputation: 319

ServiceStack PostFIleWithRequest "has" hard coded content-disposition name field

I have an issue with the PostFileWithRequest<> method in ServiceStack in that the name of the file field is hard coded to the word "upload">

Part of the data stream

Content-Disposition: form-data;name="upload";filename="Julie.mp3"

And this is from line 407 in the file ServiceClientBase.cs

         stream.Write("Content-Disposition: form-data;name=\"{0}\";filename=\"{1}\"{2}{3}".FormatWith(new object[] { "upload", fileName, text, text }));

This is contained in a virtual method but I do not know how I can change that in a derived class as there are other methods that are not accessible to my new class.

public virtual TResponse PostFileWithRequest<TResponse>(string relativeOrAbsoluteUrl, Stream fileToUpload, string fileName, object request)

Any ideas?

This look like a bug to me as the name of the form-data;name should be configurable and not hard coded.

In my case I need the file to be in a name called "File" in order to use a specific API.

Chris

Upvotes: 3

Views: 268

Answers (1)

Scott
Scott

Reputation: 21501

I submitted a pull request to ServiceStack (albeit v4) which has been accepted and will be included in the next version 4.0.14.

This adds an optional parameter of fieldName to the PostFileWithRequest<TResponse> method which allows you to specify the field name instead of being stuck with upload.

So the new signature of the method:

public virtual TResponse PostFileWithRequest<TResponse>(string relativeOrAbsoluteUrl, Stream fileToUpload, string fileName, object request, string fieldName = "upload")

Upvotes: 1

Related Questions