private HttpRequestMessage BuildMultiPartRequest(BoxMultiPartRequest request) { var httpRequest = new HttpRequestMessage(HttpMethod.Post, request.AbsoluteUri); var multiPart = new MultipartFormDataContent(); // Break out the form parts from the request var filePart = request.Parts.Where(p => p.GetType() == typeof(BoxFileFormPart)) .Select(p => p as BoxFileFormPart) .FirstOrDefault(); // Only single file upload is supported at this time var stringParts = request.Parts.Where(p => p.GetType() == typeof(BoxStringFormPart)) .Select(p => p as BoxStringFormPart); // Create the string parts foreach (var sp in stringParts) { multiPart.Add(new StringContent(sp.Value), ForceQuotesOnParam(sp.Name)); } // Create the file part if (filePart != null) { var fileContent = new ReusableContent(filePart.Value); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = ForceQuotesOnParam(filePart.Name), FileName = ForceQuotesOnParam(filePart.FileName) }; multiPart.Add(fileContent); } httpRequest.Content = multiPart; return(httpRequest); }
private HttpRequestMessage BuildBinaryRequest(BoxBinaryRequest request) { var httpRequest = new HttpRequestMessage { RequestUri = request.AbsoluteUri, Method = GetHttpMethod(request.Method) }; HttpContent content = null; var filePart = request.Part as BoxFilePart; if (filePart != null) { content = new ReusableContent(filePart.Value); } httpRequest.Content = content; return(httpRequest); }