I am trying to upload a file using an httpClient as an octet-stream
- Following documentation is provided
- HTTP Verb => POST
- Content–Type => application/octet-stream
- Accept => application/json
- Authorization => Bearer {access token}
- x-file-name => Test file.pdf
- x-convert-document (optional) => true
- x-source => the source (can be any string)
- Request Body => file (binary Stream)
Side note : in my code below the Accept and Bearer headers and their values are already present in the Client I am fetching with the "await GetRestClientAsync()"
I expect a response back, but for now I am getting nothing back the application just stops, what am I doing wrong here?
Ps: Other Posts, request towards this api work fine with the same client I use here, so it's most likely that I am messing something up with the MultiPartFormDataContent
protected async Task<TResponse> ExecutePostAsBinaryCustomHeadersAsync<TResponse>(Uri apiUri, Stream fileStream, string fileName ,bool returnDefaultObjectForInternalServerError = false)
{
using (var formData = new MultipartFormDataContent())
{
formData.Add(new StringContent(fileName), "x-file-name");
formData.Add(new StringContent("true"), "x-convert-document");
formData.Add(new StringContent("Agion"), "x-source");
formData.Add(new StringContent("application/octet-stream"), "Content-Type");
using (var client = await GetRestClientAsync())
{
StreamContent content = new StreamContent(fileStream);
formData.Add(content, "file", fileName);
using (var response = await client.PostAsync(apiUri, formData))
{
return await DeserializeResponseAsync<TResponse>(response, returnDefaultObjectForInternalServerError);
}
}
}
}