Open ojacobse opened 2 years ago
I'm having the same issue on mac. can you please share the code that you used that worked for you?
Well... for the next generations, here is is
private async Task UploadFile(string fileUri, string fileContent, string fileType, string projectId, string token)
{
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.smartling.com");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
// Prepare form data
var formData = new MultipartFormDataContent();
formData.Add(new StringContent(fileType), "fileType");
formData.Add(new StringContent(fileUri), "fileUri");
formData.Add(new ByteArrayContent(Encoding.UTF8.GetBytes(fileContent)), "file", fileUri);
// Make the API call
HttpResponseMessage response = await client.PostAsync($"/files-api/v2/projects/{projectId}/file", formData);
// Check the response
if (!response.IsSuccessStatusCode)
{
Console.WriteLine($"Failed to upload file. Status code: {response.StatusCode}");
string errorMessage = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error message: {errorMessage}");
}
}
}
When running the code under .net 6 (not tested other versions) the code fails when running under Linux.
Note: For others in the same situation I solved it by overriding the
FileApiClient.UploadFileContents(...)
But use theHttpClient
withHttpRequestMessage
andMultipartFormDataContent
.Request (Captured by proxy)
Response when running the test on Windows
HTTP/1.1 200 OK
Response when running the test on Linux
HTTP/1.1 400 Bad Request