Skip to content

Conversation

@ChamroeunProMaxQ
Copy link

This PR introduces the ability to rename uploaded files before saving them to local storage, addressing the feature request outlined in Issue #14.

Changes:

Added filename callback: A new filename option has been introduced in the FormDataInterceptorConfig interface. This callback allows users to define custom filenames for uploaded files.

filename: (originalName: string) => string;

If not provided, the system generates a unique filename by appending a salt to the original name.

Updated FileSystemStoredFile class: The FileSystemStoredFile class now accepts the filename callback. If the callback is provided in the configuration, it is used to determine the file's name before saving.

static async create(
busboyFileMeta: ParticleStoredFile,
stream: ReadableStream,
config: FormDataInterceptorConfig
): Promise<FileSystemStoredFile> {
const fileName = config.filename
  ? config.filename(busboyFileMeta.originalName)
  : FileSystemStoredFile.makeFileNameWithSalt(busboyFileMeta.originalName);
}

Benefits

  • Customizable filenames: Define naming conventions for uploaded files.
  • Prevent collisions: Unique names reduce the risk of overwriting existing files.
  • Safe for Linux/Ubuntu: Long or unsafe filenames are truncated and sanitized.
  • Improved file management: Filenames can include relevant metadata for easier identification.

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