public async Task <string> UploadFileAsync(string filePath) { using (var client = CreateHttpClient(await _tokenProvider.GetAccessTokenAsync())) { using (var content = new MultipartFormDataContent()) { var file = File.ReadAllBytes(filePath); var fileName = Path.GetFileName(filePath); var fileContent = new ByteArrayContent(file); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; content.Add(fileContent); var url = "web-api/operation/file"; var response = await client.PostAsync(url, content); ThrowIfNotSuccessful(response); var result = await response.Content.ReadAsAsync <FileUploadResult>(); return(result.FileId); } } }
protected async Task <string> PostOperationAsync <TRequest>(string url, TRequest request) { using (var client = CreateHttpClient(await _tokenProvider.GetAccessTokenAsync())) { var s = JObject.FromObject(request).ToString(); var formatter = new JsonMediaTypeFormatter(); formatter.SerializerSettings = new JsonSerializerSettings { Formatting = Formatting.Indented, ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, }; client.DefaultRequestHeaders.Accept.ParseAdd("application/json"); var response = await client.PostAsync(url, request, formatter); ThrowIfNotSuccessful(response); var result = await response.Content.ReadAsAsync <OperationResponse>(); return(result.OperationId); } }