private void SetContentDispositionHeader(ApiResponse response, IRestResponse <TResponse> restResponse) { var header = response.Headers.GetHeader(HttpResponseHeaderConstants.ContentDisposition); if (header != null && header.HasValue == true) { var contentDisposition = new ContentDispositionHeader(header.Value); response.Headers.ContentDisposition = contentDisposition; if (response.DownloadFile != null) { string fileName = contentDisposition.FileName; string contentType = _mimeMapper.GetMimeMapping(fileName); response.DownloadFile.ContentType = contentType; response.DownloadFile.FileName = fileName; response.DownloadFile.Size = restResponse.ContentLength; } } }
/// <summary> /// Set the upload file on the request and execute request /// </summary> /// <param name="request">The request</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The response</returns> public Task <ApiResponse <TResponse> > Execute(ApiRequest <TRequest> request, CancellationToken cancellationToken) { Argument.NotNull(request, nameof(request)); bool isFileUpload = _attribute != null; if (isFileUpload == true) { request.IsFileUpload = isFileUpload; bool mapped = false; foreach (var mapper in _mappers) { mapped = mapper.Map(request); if (mapped == true) { break; } } if (mapped == false) { throw new InvalidOperationException("Failed to map upload file request"); } // Set Content-Type if empty if (string.IsNullOrEmpty(request.UploadFile.ContentType) == true && string.IsNullOrEmpty(request.UploadFile.FileName) == false) { request.UploadFile.ContentType = _mimeMapper.GetMimeMapping(request.UploadFile.FileName); } request.UploadFile.ParameterName = _attribute.FileParameterName; } return(_apiClient.Execute(request, cancellationToken)); }