Orchestrator :: UploadPackage API

I am trying to upload a package to the Orchestrator using the UploadPackage API but in that I am facing some issues. The issue is like if the new package is getting added then it is successfull adding but when same package i am trying to update then I am getting error as 500 - InternalServerError.

Below i am using code to set the MultiPartBoundary and providing the Stream:

TheStreamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue(“form-data”)
Name = ““file””,
FileName = “”" + uploadFileName + “”"
TheStreamContent.Headers.ContentType = new MediaTypeHeaderValue(“application/octet-stream”);
string boundary = “–MultipartBoundry–”;
MultipartFormDataContent content = new MultipartFormDataContent(boundary);
content.Headers.TryAddWithoutValidation(“Content-Type”, “multipart/form-data; boundary=–MultipartBoundry–”);