From fbe6d0ffc9d43addd34cb8dbb20085856b62ebc1 Mon Sep 17 00:00:00 2001 From: michele Date: Thu, 2 Oct 2025 16:14:05 +0200 Subject: [PATCH] metodo upload foto --- ApiPolo/Controllers/PoloController.cs | 49 ++++++++++++++++++++++++++- ApiPolo/appsettings.json | 4 +++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/ApiPolo/Controllers/PoloController.cs b/ApiPolo/Controllers/PoloController.cs index 2db27fc..9ecc67b 100644 --- a/ApiPolo/Controllers/PoloController.cs +++ b/ApiPolo/Controllers/PoloController.cs @@ -13969,7 +13969,7 @@ namespace ApiPolo.Controllers transaction.Commit(); } //devo fare la copia del logo e metterlo nella cartella del server a partire dal logo scritto in tabella - model = await readImgAndSave(model.azienda, model.tecnico, _confLette.path_buoni); + //model = await readImgAndSave(model.azienda, model.tecnico, _confLette.path_buoni); return StatusCode(StatusCodes.Status200OK, model); } @@ -14091,6 +14091,51 @@ namespace ApiPolo.Controllers //System.IO.File.WriteAllBytes("Foo.txt", data); } + [HttpPost("datiazienda/upload_logo")] + public async Task UploadLogo(IFormFile file, string token) + { + string ten = getClaimValueByToken(token, "tenant"); + string ten2 = getClaimValueByToken(token, "tenant2"); + + if (file == null || file.Length == 0) + return BadRequest("Nessun file ricevuto"); + + if (string.IsNullOrWhiteSpace(ten2)) + return BadRequest("Parametro azienda mancante"); + + try + { + string basePath = _configuration["Percorsi:PathLogo"]; + string publicBaseUrl = _configuration["Percorsi:PublicBaseUrl"]; + + string aziendaFolder = ten2.Trim(); + string folderPath = Path.Combine(basePath, aziendaFolder); + if (!Directory.Exists(folderPath)) + Directory.CreateDirectory(folderPath); + + string fullPath = Path.Combine(folderPath, file.FileName); + + using (var stream = new FileStream(fullPath, FileMode.Create)) + { + await file.CopyToAsync(stream); + } + + string fileUrl = $"{publicBaseUrl}{aziendaFolder}/{file.FileName}"; + + return Ok(new + { + message = "Logo caricato con successo", + url = fileUrl, + fileName = file.FileName + }); + } + catch (Exception ex) + { + return StatusCode(500, $"Errore durante il salvataggio: {ex.Message}"); + } + } + + /// VIRTUAL TASK: ricava il nome del file a partire dal path web public static string getNomeFile(string path) { @@ -14101,6 +14146,8 @@ namespace ApiPolo.Controllers return nome; } + + /// VIRTUAL TASK: dati Azienda [HttpGet("rapportiniList")] public async Task>> rapportiniList(string token) diff --git a/ApiPolo/appsettings.json b/ApiPolo/appsettings.json index 22a8136..0181d90 100644 --- a/ApiPolo/appsettings.json +++ b/ApiPolo/appsettings.json @@ -23,5 +23,9 @@ "ValidAudience": "http://localhost:4200", "ValidIssuer": "http://localhost:61955", "Secret": "ByYM000OLlMQG6VVVp1OH7Xzyr7gHuw1qvUC5dcGt3SNM" + }, + "Percorsi": { + "PathLogo": "/zucchetti/api/api-vt.poloinformatico.it/app/wwwroot/VIRTU/", + "PublicBaseUrl": "https://api-vt.poloinformatico.it/VIRTU/" } }