Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add File and Image Upload WebAPI Endpoint #11

Merged
merged 11 commits into from
Nov 30, 2024
Merged

Add File and Image Upload WebAPI Endpoint #11

merged 11 commits into from
Nov 30, 2024

Conversation

neozhu
Copy link
Owner

@neozhu neozhu commented Nov 29, 2024

image

PR# - Add File and Image Upload WebAPI Endpoint

Description

This PR introduces a new WebAPI for file and image uploads, implemented in the FileUploadEndpointRegistrar.cs class. The endpoints allow users to upload files and images to the server with additional functionality like cropping images and managing file paths. It also includes endpoints for retrieving and deleting files from the server.


Key Features:

  1. File Upload Endpoint:

    • Route: /file/upload
    • Request: FileUploadRequest containing file details, target folder, and overwrite option.
    • Response: List of FileUploadResponse objects with file details (URL, path, size).
    • Supports multiple file uploads with metadata like file size and URL.
  2. Image Upload Endpoint with Cropping:

    • Route: /file/image
    • Request: ImageUploadRequest with optional cropping dimensions.
    • Response: List of FileUploadResponse objects for uploaded images.
    • Additional Feature: Crop uploaded images based on the provided dimensions using the SixLabors.ImageSharp library.
  3. File Retrieval Endpoint:

    • Route: /file/
    • Functionality: Allows clients to preview or download a file based on its path.
  4. File Deletion Endpoint:

    • Route: /file/
    • Functionality: Deletes a file from the server based on its path.

Highlights:

  • Authorization is required for all endpoints using .RequireAuthorization().
  • Validation for input parameters ensures folder paths, file existence, and cropping dimensions are handled securely.
  • Implements antiforgery protection and returns standardized HTTP responses for different scenarios (e.g., validation errors, not found).
  • Utilizes IUploadService to manage file storage and operations.

Classes Added:

  1. FileUploadRequest: Defines the structure for file upload requests.
  2. FileUploadResponse: Provides details about uploaded files in the response.
  3. ImageUploadRequest: Extends FileUploadRequest with additional cropping options.
  4. CropSize: Represents cropping dimensions for image uploads.

How to Test:

  1. File Upload:

    • Send a POST request to /file/upload with a multipart/form-data request containing files.
    • Validate that the response contains URLs and paths for uploaded files.
  2. Image Upload with Cropping:

    • Send a POST request to /file/image with a multipart/form-data request containing images and optional crop dimensions.
    • Validate that images are cropped and stored as expected.
  3. Retrieve File:

    • Send a GET request to /file/?path=<file_path>.
    • Validate the file can be downloaded or previewed.
  4. Delete File:

    • Send a DELETE request to /file/?path=<file_path>.
    • Validate the file is removed from the server.

@neozhu neozhu merged commit cfec1ea into main Nov 30, 2024
3 of 4 checks passed
@neozhu neozhu deleted the feature/fileupload branch November 30, 2024 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant