Aggiunto metodo controller GET x file download
This commit is contained in:
@@ -4,8 +4,8 @@ using LiMan.DB.DBModels;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -43,7 +43,6 @@ namespace LiMan.APi.Controllers
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="DataService"></param>
|
||||
/// <param name="env"></param>
|
||||
/// <param name="logger"></param>
|
||||
public FilesaveController(IConfiguration configuration, ApiDataService DataService, IWebHostEnvironment env)
|
||||
{
|
||||
dataService = DataService;
|
||||
@@ -63,15 +62,61 @@ namespace LiMan.APi.Controllers
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Public Methods
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Richiesta di registrazione ticket supporto
|
||||
/// Calcolo correetto mimetype da nome file
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
protected string GetMimeType(string fileName)
|
||||
{
|
||||
var provider = new FileExtensionContentTypeProvider();
|
||||
string contentType;
|
||||
if (!provider.TryGetContentType(fileName, out contentType))
|
||||
{
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
return contentType;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// GET api/filesave/id/filename
|
||||
/// <summary>
|
||||
/// Recupera un singolo file dato ticket code + nome file (safe)
|
||||
/// </summary>
|
||||
/// <param name="id">Ticket code formato T00000000</param>
|
||||
/// <param name="secureName">Nome file (safe)</param>
|
||||
/// <param name="fileName">Nome file da scaricare</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/{secureName}/{fileName}")]
|
||||
public async Task<ActionResult> DownloadFile(string id, string secureName, string fileName)
|
||||
{
|
||||
string relDir = _configuration["FileShare"];
|
||||
string ticketDir = Path.Combine(relDir, id);
|
||||
var filePath = Path.Combine(ticketDir, secureName);
|
||||
// verifico esistenza..
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
var bytes = await System.IO.File.ReadAllBytesAsync(filePath);
|
||||
return File(bytes, GetMimeType(fileName), fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return File(new byte[0], "text/plain", "Empty.txt");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco files assaociati a ticket supporto
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="CurrRequest"></param>
|
||||
/// <returns></returns>
|
||||
// POST api/files/list/1
|
||||
// POST api/filesave/list/1
|
||||
[HttpPost("list/{id}")]
|
||||
public async Task<List<FileAttachModel>> list(int id, [FromBody] SupportRequest CurrRequest)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user