Blazor3D icon indicating copy to clipboard operation
Blazor3D copied to clipboard

Added the ability to upload local files via the controller

Open anomal3 opened this issue 1 year ago • 0 comments

Hey)) Unfortunately you do not have a separate branch. And I also ask you to consider a method that allows you to download files not only via a link, but also to be able to download files locally. In my approach, this comes in handy because I scan from Lidar and upload files to the server, and then I can view them using the 3D viewing tool.

This method works through a controller to which we pass the path to the file on the local disk

[Route("api/[controller]")]
[ApiController]
public class FileController : Controller
{
    /// <summary>
    /// Addition as a controller for accessing local files
    /// </summary>
    /// <param name="link">Full path local file</param>
    /// <returns></returns>
    [HttpGet("[action]")]
    public IActionResult FileDownload([FromQuery] string link)
    {
        var saveFileName = link.Substring(link.LastIndexOf('\\') + 1);
        try
        {
            var fileBytes = System.IO.File.ReadAllBytes(link);
            var contentType = "APPLICATION/octet-stream";
            var fileName = saveFileName;
            return File(fileBytes, contentType, fileName);
        }
        catch (Exception ex)
        {
            return StatusCode(StatusCodes.Status500InternalServerError, "Error download: " + ex.Message);
        }
    }
}

LocalLoad

anomal3 avatar Apr 02 '24 20:04 anomal3