restsharp / RestSharp

Simple REST and HTTP API Client for .NET
https://restsharp.dev
Apache License 2.0
9.61k stars 2.34k forks source link

Adding Attachments to ServiceNow is not working (corrupted) in version latest 112 #2261

Open sobhanrao opened 1 month ago

sobhanrao commented 1 month ago

I am facing challenges after migrating from RestSharp version 106.11.4 to 112, specifically when adding attachments to ServiceNow incidents. The code that was working fine in 106.11.4 is now leading to corrupted data in the attachments after the migration.

Use the following code, which worked in version 106.11.4 working as expected.

request.AddParameter("Content-Type", "image/png"); request.Parameters.Add(new Parameter("image/png", byteArrayData, ParameterType.RequestBody));

After migrating to RestSharp 112, modify the code as follows to attempt the attachment and its failing, attachment added but corrupted.

request.AddParameter("Content-Type", "image/png"); Tried several approaches one by one all below methods, but none worked:

request.AddParameter("image/png", data, ParameterType.RequestBody);
request.AddFile("file", byteArrayData, fileName, "image/png");
request.AddFile(fileName, @"C:\Work\arrow-106-16.png", "image/png");

Please let me know if there are any specific changes in how RestSharp handles file uploads between these versions or if there is a different recommended approach in version 112.

sobhanrao commented 1 month ago

Tried this with both .Net Framework 4.8 and .Net Core 8.

alexeyzimarev commented 1 month ago

AddFile should work. There are tests that upload files and they all pass.

What kind of corruption do you observe? It'd be nice to know the details. Maybe you can also use requestbin to compare calls made by RS 106 and 112.