Using django-storages S3 implementation for Minio with s3v4 signature

I have "successfully" set up django-storages to work with our self hosted Minio instance.

This is the settings for the setup:

STORAGES = {
    "default": {
        "BACKEND": "storages.backends.s3.S3Storage",
        "OPTIONS": {
            "endpoint_url": os.getenv("MINIO_ENDPOINT_URL"),
            "access_key": os.getenv("MINIO_ACCESS_KEY"),
            "secret_key": os.getenv("MINIO_SECRET_KEY"),
            "bucket_name": os.getenv("MINIO_BUCKET_NAME"),
            "region_name": os.getenv("MINIO_REGION_NAME"),
            "signature_version": os.getenv("MINIO_SIGNATURE_VERSION", "s3v4"),
        },
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    },
}

The region is eu-central-1 which does support the v4 signature for S3.

Everything is set up correctly, the endpoint, keys, bucket name, and correctly read from .env when printed out in settings.

Now, this completely works when trying to get files, all the files are fetched normally, I can see them in the console, the generated signed URLs work, all is fine.

The issue comes when trying to POST/upload a multipart/form-data endpoint that contains a file. When I attempt to do so through the swagger UI, I get the following error:

ClientError at /files/uploaded-files/
An error occurred (XAmzContentSHA256Mismatch) when calling the PutObject operation: The provided 'x-amz-content-sha256' header does not match what was computed.

I have deduced the issue is with the signature version, because once I switch the signature to s3 from s3v4, both the upload and fetching of the files works correctly.

But from what I understood, I should strive to use s3v4 as s3 signatures are deprecated and less secure.

Does anyone have any idea what the issue or fix might be? Could it be with minio, my configuration, etc..

Thank you in advance.

Вернуться на верх