0

I am trying to upload a PNG file using the Zendesk Attachments API and Restsharp. It seems to upload fine but when I click the content url it says the image cannot be displayed because it contains an error.

I am able to upload a pdf by using the same call after changing the file extensions to pdf and it works fine.

            var request = new RestRequest("uploads.json? filename=file1.png", Method.POST);
            request.AddHeader("Content-Type", "application/binary");
            request.AddHeader($"Authorization", "Basic {config.api}");
            request.AddFile("file1", path, "image/png");
            var response = client.Execute(request);

The api call is successful but when I look at the content URL that is returned from the call I get "Image can't be displayed because it contains errors".

Jerkstore
  • 1
  • 1

1 Answers1

0

I figured this out finally. Here is the solution: https://stackoverflow.com/a/45382624

I removed these two lines:

request.AddHeader("Content-Type", "application/binary");
request.AddFile("file1.png", path, "application/binary");

And added this line:

request.AddParameter("application/binary", File.ReadAllBytes(pathToFile), ParameterType.RequestBody);

Now it works with all file types.

Jerkstore
  • 1
  • 1