public async Task <IActionResult> LabelLoaderIngredients(AddLabelImage addLabelImage) { try { _logger.LogInformation($"Iniciando extração de ingredientes item {addLabelImage.ItemName}," + $" imagem {addLabelImage.ItemName }"); if (!ValidFile(addLabelImage.File)) { return(NotFound(":(")); } LabelImageAdded labelImageAdded = new LabelImageAdded() { ItemName = addLabelImage.ItemName, Ingredients = await _extractIngredientsService.GetIngredients(addLabelImage.File) }; _sendIngredientsService.SendIngredients(labelImageAdded); _logger.LogInformation("Extração finalizada"); return(Ok()); } catch (Exception ex) { _logger.LogError($"Falha no processo de extração de ingredientes {ex.ToString()}"); return(NotFound()); } }
/// <summary> /// Enviar arquivo para API /// </summary> /// <param name="arquivo">Dados do arquivo que será enviado</param> /// <returns>bool</returns> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.IO.PathTooLongException"></exception> /// <exception cref="System.IO.DirectoryNotFoundException"></exception> /// <exception cref="System.IO.IOException"></exception> /// <exception cref="System.UnauthorizedAccessException"></exception> /// <exception cref="System.IO.FileNotFoundException"></exception> /// <exception cref="System.NotSupportedException"></exception> /// <exception cref="System.Security.SecurityException"></exception> private async Task <bool> EnviarParaApi(FileInfo arquivo) { try { var arquivoConvertido = File.ReadAllBytes(arquivo.FullName); AddLabelImage imagem = new AddLabelImage { ItemName = arquivo.Name, File = Convert.ToBase64String(arquivoConvertido) }; using (var client = HttpClientFactory.CreateClient("ApiAzure")) { Logger.LogInformation($"Enviando arquivo para: {Url("api/Ingredient")}"); System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken(); var resposta = await client.PostAsJsonAsync("api/Ingredient", imagem, cancellationToken); if (resposta.IsSuccessStatusCode) { Logger.LogInformation($"Arquivo [{arquivo.FullName}] enviado com sucesso para: {Url("api/Ingredient")}. StatusCode {(int)resposta.StatusCode} - {resposta.StatusCode}"); return(true); } else { Logger.LogError($"Arquivo [{arquivo.FullName}] não enviado para: {Url("api/Ingredient")}. Error: {Convert.ToInt32(resposta.StatusCode)} - {resposta.StatusCode}"); return(false); } } } catch (Exception ex) { Logger.LogError($"Erro ao enviar o arquivo [{arquivo.FullName}]: {ex.ToString()}"); throw; } }
public IActionResult AddLabel(AddLabelImage label) { return Ok(); }