File Storage Design

In our restaurant review platform, users need to upload photos of their dining experiences.

Let's design a simple yet effective way to handle file storage that will serve as the foundation for our photo upload feature.

Understanding File Storage Options

When building web applications that handle file uploads, you have multiple storage options available.

The most straightforward approach is saving files directly to the server's disk.

While cloud storage services like AWS S3 or Azure Blob Storage are popular choices, we'll start with local disk storage to keep our implementation focused and manageable.

Designing the Storage Service

The storage service needs to handle two primary operations: storing uploaded files and retrieving them when needed.

Let's create a service interface that defines these operations:

package com.devtiro.restaurant.services; import org.springframework.core.io.Resource; import org.springframework.web.multipart.MultipartFile; import java.util.Optional; public interface StorageService { // Store a file and return its unique identifier String store(MultipartFile file, String filename); // Retrieve a file by its identifier Optional<Resource> loadAsResource(String filename); }

Let's break down the interface methods:

  • The store method accepts a MultipartFile (Spring's representation of an uploaded file) and a filename, returning a String identifier
  • The loadAsResource method takes a filename and returns an Optional<Resource>, allowing for cases where the file might not exist

Summary

  • Created StorageService interface for managing file operations
  • Defined methods for storing and retrieving files from disk
© 2026 Devtiro Ltd. All rights reserved