Commit 7eff3732 authored by Alessio Parma's avatar Alessio Parma

txt files

parent c4f5603f
Pipeline #146925230 passed with stages
in 39 minutes and 20 seconds
......@@ -29,6 +29,7 @@
using Flurl;
using Flurl.Http;
using Microsoft.Extensions.Options;
using PommaLabs.MimeTypes;
using PommaLabs.Thumbnailer.Client.Models.Configurations;
using PommaLabs.Thumbnailer.Client.Models.Enumerations;
using PommaLabs.Thumbnailer.Client.Models.Exceptions;
......@@ -88,12 +89,14 @@ public sealed class ConcreteThumbnailerClient : IThumbnailerClient
_validator.ValidateFileBytes(bytes);
_validator.ValidateContentTypeForThumbnailGeneration(contentType, @throw: true);
var fileName = $"{Path.GetRandomFileName()}{MimeTypeMap.GetExtension(contentType)}";
return await EvaluateResponseAsync(OperationType.ThumbnailGeneration, async () => await Url
.Combine(_clientConfiguration.Value.BaseUri.AbsoluteUri, "api/v1/thumbnail")
.WithHeader(ApiKeyHeaderName, _clientConfiguration.Value.ApiKey)
.SetQueryParam(nameof(sidePx), sidePx.ToString(CultureInfo.InvariantCulture))
.SetQueryParam(nameof(shavePx), shavePx.ToString(CultureInfo.InvariantCulture))
.PostMultipartAsync(mp => mp.AddFile("file", new MemoryStream(bytes), Path.GetRandomFileName(), contentType), cancellationToken)
.PostMultipartAsync(mp => mp.AddFile("file", new MemoryStream(bytes), fileName, contentType), cancellationToken)
.ReceiveBytes()
.ConfigureAwait(false))
.ConfigureAwait(false);
......@@ -135,10 +138,12 @@ public Task<bool> IsThumbnailGenerationSupportedAsync(string contentType)
_validator.ValidateFileBytes(bytes);
_validator.ValidateContentTypeForImageOptimization(contentType, @throw: true);
var fileName = $"{Path.GetRandomFileName()}{MimeTypeMap.GetExtension(contentType)}";
return await EvaluateResponseAsync(OperationType.ImageOptimization, async () => await Url
.Combine(_clientConfiguration.Value.BaseUri.AbsoluteUri, "api/v1/optimize")
.WithHeader(ApiKeyHeaderName, _clientConfiguration.Value.ApiKey)
.PostMultipartAsync(mp => mp.AddFile("file", new MemoryStream(bytes), Path.GetRandomFileName(), contentType), cancellationToken)
.PostMultipartAsync(mp => mp.AddFile("file", new MemoryStream(bytes), fileName, contentType), cancellationToken)
.ReceiveBytes()
.ConfigureAwait(false))
.ConfigureAwait(false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment