Skip to main content

Overview

The UploadFilesController provides functionality for uploading files to the server. It uses the HelperPathProvider to manage file paths and storage locations.

Constructor

UploadFilesController

Initializes a new instance of the controller with path management capabilities.
helper
HelperPathProvider
required
Helper service for mapping file paths and URL paths
public UploadFilesController(HelperPathProvider helper)
Source: /workspace/source/MvcCoreUtilidades/Controllers/UploadFilesController.cs:10

Methods

Index

Displays the main upload files view.
public IActionResult Index()
IActionResult
IActionResult
Returns the Index view
Source: /workspace/source/MvcCoreUtilidades/Controllers/UploadFilesController.cs:15

SubirFile (GET)

Displays the file upload form.
public IActionResult SubirFile()
IActionResult
IActionResult
Returns the SubirFile view
Source: /workspace/source/MvcCoreUtilidades/Controllers/UploadFilesController.cs:20

SubirFile (POST)

[HttpPost] Handles file upload by saving the file to the server and returning the file path information.
[HttpPost]
public async Task<IActionResult> SubirFile(IFormFile fichero)
fichero
IFormFile
required
The file to upload from the HTTP request
IActionResult
Task<IActionResult>
Returns the SubirFile view with ViewData containing:
  • MENSAJE: Success message with the file path
  • URLPATH: The URL path where the file can be accessed
Behavior:
  • Extracts the filename from the uploaded file
  • Maps the physical path using HelperPathProvider.MapPath() with Folders.Images
  • Creates a URL path using HelperPathProvider.MapUrlPath()
  • Saves the file asynchronously using a FileStream
  • Sets ViewData with the file path and URL information
Source: /workspace/source/MvcCoreUtilidades/Controllers/UploadFilesController.cs:25

Build docs developers (and LLMs) love