Share via

HttpClient Post zip file to Sharepoint Rest API results in corrupt zip file

Neal Anthony 1 Reputation point
2022-02-25T21:13:43.23+00:00

Good afternoon. I have an Azure function that is triggered when a blob drops into a blob container in an azure storage account. The function uses an HttpClient library asynchronous post to sharepoint via the sharepoint REST API. When I download the resulting zip file from Sharepoint, I am unable to open the file with Windows extractor (it will open with WinRar, but that is not the end goal). I then use a utility to open the same file in my Azure storage and compare with the file that I sent to Sharepoint. The Sharepoint file has additional header data in it. If I manually remove the header data from the corrupted file, I can open the file with Windows Extractor. A little further information, the additional header in the corrupt file is the content-disposition header.

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Neal Anthony 1 Reputation point
    2022-03-04T19:59:27.037+00:00

    Thank You for following up. I switched to HttpClientFactory and everything started working. Thank You for your help.

    Was this answer helpful?

    0 comments No comments

  2. MughundhanRaveendran-MSFT 12,511 Reputation points
    2022-02-28T17:18:21.797+00:00

    @Neal Anthony ,

    Thanks for reaching out to Q&A forum.

    You can remove the header using the below code programmatically

    HttpContext.Current.Response.Headers.Remove("Header-name");

    Similar discussion here: https://stackoverflow.com/questions/3418557/how-to-remove-asp-net-mvc-default-http-headers

    Please note that, this issue is not related to Azure functions. You should be able reproduce this issue outside the Azure environment as well.

    I hope this helps!

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.