Is there any way to add a file as part of a multiformdatacontent:
Currently I have something like that (obviously used with a HttpClient):
const string formDataKey = @"""file""";
var formDataValue = $@"""{inputFileName}""";
var xmlInput = File.ReadAllText(inputFilePath);
var xmlInputBytes = Encoding.ASCII.GetBytes(xmlInput);
var byteArrayContent = new ByteArrayContent(xmlInputBytes);
byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue(inputType);
var multipartFormDataContent = new MultipartFormDataContent
{
{ byteArrayContent, formDataKey, formDataValue }
};
return multipartFormDataContent;
How does it translate with the refit paradigm?
Bumping this issue. I wrote the question in StackOverflow like this https://stackoverflow.com/questions/51753141/multipart-content-with-refit
When I try use Multipart it always showing the exception.
Stack OverflowI am using multipart with Refit. I try to upload profile picture for my service the code generated from postman is looking like this var client = new RestClient("http://api.example.com/api/users/1...
Hi @albilaga Maybe a dumb question but do you have a global content type set in your Refit Implementation?
Hi @ehouarn-perret,
please have a look at https://github.com/reactiveui/refit#multipart-uploads.
You will either need a StreamPart or a ByteArrayPart with the name of file in the request.
Then decorate your request with the multipart attribute.
GitHub
refit - The automatic type-safe REST library for Xamarin and .NET
@vatsalyagoel , thanks I know I will try this out whenever I can
@vatsalyagoel No I don't set any global content type
Most helpful comment
Bumping this issue. I wrote the question in StackOverflow like this https://stackoverflow.com/questions/51753141/multipart-content-with-refit
When I try use Multipart it always showing the exception.