Skip to content

Conversation

@mgajda
Copy link
Contributor

@mgajda mgajda commented Dec 15, 2025

Summary

This PR enhances the Storage Import functionality to support additional IANA-registered content types as documented in the UpCloud Storage Import API.

Changes

  1. Extended Content Type Support

    • Added support for: application/x-tar, application/x-bzip2, application/x-7z-compressed, application/zip
    • Auto-detection from file extensions
    • Default to application/octet-stream for unknown types
  2. New --content-type Flag

    • Allows explicit specification of content type
    • Example: upctl storage import --source-location file.tar --content-type application/x-tar --title my_storage --zone es-mad1
  3. Improved Help Text

    • Both --source-location and --content-type flags now dynamically display supported formats
    • Extracted content type mapping to package level for reusability

Testing

  • All existing tests pass
  • Added comprehensive unit tests for content type detection
  • Build verification successful

Supported File Types

Extension Content Type
.gz application/gzip
.xz application/x-xz
.tar application/x-tar
.bz2 application/x-bzip2
.7z application/x-7z-compressed
.zip application/zip
.iso, .img, .raw, .qcow2 application/octet-stream

How to Test

# Auto-detect content type
upctl storage import --source-location archive.tar.gz --title test --zone es-mad1

# Explicit content type
upctl storage import --source-location file.tar --content-type application/x-tar --title test --zone es-mad1

# View supported types in help
upctl storage import --help

For #581 client-side uploads only. The custom content type is not yet supported for URL-based import.

…content-type flag

- Support IANA-registered content types: application/gzip, application/x-xz,
  application/x-tar, application/x-bzip2, application/x-7z-compressed,
  application/zip, and application/octet-stream
- Add --content-type flag to allow explicit content type specification
- Auto-detect content type from file extension with fallback to octet-stream
- Add getContentType() function for extensible content type mapping
- Add comprehensive unit tests for content type detection

Fixes UpCloudLtd#581
@mgajda mgajda requested a review from a team as a code owner December 15, 2025 07:59
- Move supportedContentTypes map to package level for reusability
- Add getSupportedExtensionsText() to list all supported file extensions
- Add getSupportedContentTypesText() to list all supported content types
- Update --source-location help to show supported extensions dynamically
- Update --content-type help to show supported types dynamically
- Simplify getContentType() to use the package-level map
- Help text now automatically reflects all supported formats
Comment on lines +31 to +40
".gz": "application/gzip",
".xz": "application/x-xz",
".iso": "application/octet-stream",
".img": "application/octet-stream",
".raw": "application/octet-stream",
".qcow2": "application/octet-stream",
".tar": "application/x-tar",
".bz2": "application/x-bzip2",
".7z": "application/x-7z-compressed",
".zip": "application/zip",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on our our docs we only support raw images and gz and xz compressions, so no need for all of these 🤔

The supported data type is raw (extension .raw, .img or .iso). However, the data can be compressed either with GZip or XZ (Content-Types application/gzip and application/x-xz, typical extensions .gz and .xz respectively) in which case it will be transparently decompressed.

mgajda added 2 commits January 1, 2026 02:02
The golangci-lint modernize linter detected inefficient string concatenation
in loops. Using strings.Builder is more efficient as it avoids creating
multiple intermediate string objects.
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.

2 participants