Skip to content

feat: create parent directories automatically in SaveUploadedFile() - #187

Open
Utkarsh0uchiha wants to merge 1 commit into
DevanshuTripathi:mainfrom
Utkarsh0uchiha:main
Open

feat: create parent directories automatically in SaveUploadedFile()#187
Utkarsh0uchiha wants to merge 1 commit into
DevanshuTripathi:mainfrom
Utkarsh0uchiha:main

Conversation

@Utkarsh0uchiha

Copy link
Copy Markdown
Contributor

Closes #183

Summary

This PR improves Context.SaveUploadedFile() by automatically creating missing parent directories before saving uploaded files.

Changes

  • Creates parent directories using os.MkdirAll() before creating the destination file.
  • Preserves the existing behavior when the destination directory already exists.
  • No changes to the public API.

Motivation

Previously, saving an uploaded file to a nested path such as:

err := c.SaveUploadedFile(file, "uploads/images/avatar.png")

would fail if the uploads/images directory did not already exist.

With this change, the required directory structure is created automatically, allowing developers to save uploaded files to nested paths without performing manual directory creation beforehand.

Tests

Added tests covering:

  • Saving a file to a nested directory that does not exist
  • Successfully creating missing parent directories
  • Verifying the uploaded file is written correctly
  • Ensuring existing directory behavior remains unchanged

All tests pass locally.

Backward Compatibility

No breaking changes.

Applications that already create destination directories manually will continue to work exactly as before, while applications saving to nested paths gain automatic directory creation.

@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

@Utkarsh0uchiha is attempting to deploy a commit to the Devanshu Tripathi's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

feat: Create parent directories automatically in SaveUploadedFile()

1 participant