2 years ago

#70732

test-img

sergiokml

when uploading file by post httpclient the file is left with wrong marks

I am uploading a csv file as follows:

string token = await GetTokenAsync();
string path = "C://...";

_httpClient.DefaultRequestHeaders.Add("Authorization", $"Token {token}");

MultipartContent content = new();
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = $"dtes_acreedor_.csv" };

string contenido = await File.ReadAllTextAsync(path);
StringContent contentData = new(contenido, Encoding.UTF8, "text/csv");
content.Add(contentData);

HttpResponseMessage response = await _httpClient.PutAsync("api/v1/resources/auxiliary-files/", content);

But then when downloading the same uploaded file and then opening it, it appears with strange characters:

csv image:

that could be happening? This is the uploaded file: https://prnt.sc/26frlqt

Edit: I put this too and still the same. It is not solved, the file continues to download badly, I have even uploaded another one that has not been formatted by me before and neither.

string contenido = await File.ReadAllTextAsync(name, Encoding.UTF8);
 StringContent contentData = new(contenido, Encoding.UTF8, "text/csv");

This is how I create the file:

File.WriteAllText(name, csv.ToString(), Encoding.UTF8);

The character thing is the least important thing, the curious and important thing about the question is the 3 rows that it adds to the beginning of the file: https://prnt.sc/26fu1ai

c#

httpclient

put

0 Answers

Your Answer

Accepted video resources