Last active
October 13, 2022 16:48
-
-
Save hallem/5faaa6bebde50641e928 to your computer and use it in GitHub Desktop.
RestSharp file as body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public RestApiResponse<bool> PutEnvelopesDocuments(string envelopeId, string documentId, string fullFileName, byte[] documentBytes) | |
{ | |
RestRequest request = GetBaseRequest("envelopes/{envelopeId}/documents/{documentId}", Method.PUT); | |
request.AddUrlSegment("envelopeId", envelopeId); | |
request.AddUrlSegment("documentId", documentId); | |
request.AddHeader("Content-Type", "application/pdf"); | |
request.AddHeader("Content-Disposition", | |
string.Format("file; filename=\"{0}\"; documentid={1}; fileExtension=\"{2}\"", | |
Path.GetFileNameWithoutExtension(fullFileName), documentId, Path.GetExtension(fullFileName))); | |
request.AddParameter("application/pdf", documentBytes, ParameterType.RequestBody); | |
var response = this.restClient.Execute(request); | |
return RestApiResponse<bool>.Create(response, this.restClient.BuildUri(response.Request)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've had a heck of a time with RestSharp these past few days trying to submit a multipart request to an api that needed to have json body with base64 pdf. I was not able to use RestSharp due to it always defaulting "multipart/form-data" as the Content-Type. I eventually was able to get HttpUtility to work. If you need to submit with multipart/related or anything other than "form-data" I'm not sure RestSharp will allow for it. If I am mistaken please correct me.