Skip to content

Instantly share code, notes, and snippets.

@icebeam7

icebeam7/ServicioStorage.cs Secret

Last active Dec 14, 2020
Embed
What would you like to do?
Servicios/ServicioStorage
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using Azure.Storage.Blobs;
using ICTalkMobileApp.Models;
namespace ICTalkMobileApp.Services
{
public class ServicioStorage
{
private const string cadenaConexionStorage = "REEMPLAZA-CADENA-CONEXION";
private const string nombreContenedor = "imagenes";
private const string funcionBusqueda = "REEMPLAZA-AZURE-FUNCTION";
BlobServiceClient clienteServicio;
BlobContainerClient clienteContenedor;
public ServicioStorage()
{
clienteServicio = new BlobServiceClient(cadenaConexionStorage);
try
{
clienteContenedor = clienteServicio.CreateBlobContainer(nombreContenedor);
}
catch (Exception ex)
{
clienteContenedor = clienteServicio.GetBlobContainerClient(nombreContenedor);
}
}
public async Task SubirImagen(string imagen)
{
using (var fs = File.Open(imagen, FileMode.Open))
{
var nombreBlob = Path.GetFileName(imagen);
await clienteContenedor.UploadBlobAsync(nombreBlob, fs);
}
}
public async Task<List<Analisis>> ObtenerImagenesSimilares(string imagen)
{
using (var clienteHttp = new HttpClient())
{
var nombre = Path.GetFileName(imagen);
var url = $"{funcionBusqueda}&nombre={nombre}";
var respuesta = await clienteHttp.GetAsync(url);
if (respuesta.IsSuccessStatusCode)
{
var json = await respuesta.Content.ReadAsStringAsync();
var lista = JsonConvert.DeserializeObject<List<Analisis>>(json);
return lista;
}
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment