67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using System.Net.Http.Json;
|
|
//using TIAM.Entities.TransferDestinations;
|
|
using TIAMWebApp.Shared.Application.Interfaces;
|
|
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
|
using TIAMWebApp.Shared.Application.Models;
|
|
|
|
namespace TIAMWebApp.Shared.Application.Services
|
|
{
|
|
public class ImageDataService : IImageDataService
|
|
{
|
|
private readonly HttpClient _http;
|
|
|
|
public ImageDataService(HttpClient httpClient)
|
|
{
|
|
_http = httpClient;
|
|
}
|
|
|
|
public async Task<List<string>> GetImagesAsync(string userId)
|
|
{
|
|
var response = await _http.GetAsync("images");
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var fileNames = await response.Content.ReadFromJsonAsync<List<string>>();
|
|
return fileNames;
|
|
}
|
|
|
|
throw new ApplicationException($"Status code: {response.StatusCode}, Error: {response.ReasonPhrase}");
|
|
}
|
|
|
|
public async Task<Stream> GetImageAsync(string name)
|
|
{
|
|
var response = await _http.GetAsync($"image/{name}");
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var stream = await response.Content.ReadAsStreamAsync();
|
|
return stream;
|
|
}
|
|
|
|
throw new ApplicationException($"Status code: {response.StatusCode}, Error: {response.ReasonPhrase}");
|
|
}
|
|
|
|
public async Task<string> UploadImageAsync(MultipartContent image)
|
|
{
|
|
var url = $"{Setting.ApiBaseUrl}/{APIUrls.UploadImage}";
|
|
var response = await _http.PostAsync(url, image);
|
|
|
|
//var result = new WizardProcessorResult();
|
|
|
|
//if (response.IsSuccessStatusCode)
|
|
//{
|
|
// result.IsSucces = true;
|
|
// result.ResultJson = await response.Content.ReadAsStringAsync();
|
|
//}
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
return "Oops, something wrong";
|
|
|
|
var result = await response.Content.ReadAsStringAsync();
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
}
|