Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a file as part of a multiformdatacontent? #539

Open
natalie-o-perret opened this issue Aug 2, 2018 · 5 comments
Open

Add a file as part of a multiformdatacontent? #539

natalie-o-perret opened this issue Aug 2, 2018 · 5 comments

Comments

@natalie-o-perret
Copy link

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?

@albilaga
Copy link

albilaga commented Aug 24, 2018

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 Overflow
I 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...

@vatsalyagoel
Copy link
Member

Hi @albilaga Maybe a dumb question but do you have a global content type set in your Refit Implementation?

@vatsalyagoel
Copy link
Member

vatsalyagoel commented Aug 27, 2018

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

@natalie-o-perret
Copy link
Author

@vatsalyagoel , thanks I know I will try this out whenever I can

@albilaga
Copy link

@vatsalyagoel No I don't set any global content type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants