Skip to content

Copy object does not update content type #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
ibash opened this issue Feb 1, 2025 · 3 comments
Closed
2 tasks done

Copy object does not update content type #628

ibash opened this issue Feb 1, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@ibash
Copy link

ibash commented Feb 1, 2025

Duplicate of #580 and #611 . The issue remains unfixed.

I'm guessing it's becauseMetadataDirective is not being set correctly.

ref: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/command/CopyObjectCommand/

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Case 1:
Steps:

  1. Copy object to a new key with a new content-type
  2. Curl the url of the new key
  3. Inspect the object in the supabase dashboard

Expected:
content-type header returned from curl are the new content type
mimetype in supabase is updated

Actual:
content-type header returned from curl is the old content type
mimetype in supabase is updated
In this case the content-type and supabase mimetype don't match

Case 2:
Steps:

  1. Copy object to the same key, but with the same content-type
  2. Curl the url of the key
  3. Inspect the object in the supabase dashboard

Expected:
content-type header returned from curl are the new content type
mimetype in supabase is updated

Actual:
Neither the content-type header or the mimetype are updated, they're both the old value

To Reproduce

  1. Upload an object to supabase storage with content-type "text/plain"
  2. Overwrite the object via the s3 protocol, but specify an alternative content type like "audio/mp4"
import { S3Client, CopyObjectCommand } from "@aws-sdk/client-s3";

const client = new S3Client({
  forcePathStyle: true,
  region: "us-west-1",
  endpoint: "supabase-s3-endpoint",
  credentials: {
    accessKeyId: process.env.ACCESS_KEY_ID,
    secretAccessKey: process.env.SECRET_ACCESS_KEY,
  },
});

const bucket = 'my-bucket'
const key = 'my-key.m4a'

const command = new CopyObjectCommand({
  Bucket: bucket,
  CopySource: `${bucket}/${key}`,
  Key: key,
  ContentType: 'audio/mp4'
});

const data = await client.send(command);

console.log('data is ', data)

Expected behavior

Content-type when curling and mimetype in supabase are both updated.

Additional context

This is a continuation of #580, but creating a new issue so it's not missed since that was marked completed.

@ibash ibash added the bug Something isn't working label Feb 1, 2025
@ibash
Copy link
Author

ibash commented Feb 25, 2025

@fenos any chance we can get a fix for this?

@fenos
Copy link
Contributor

fenos commented Mar 12, 2025

Hey, @ibash the work for this is already done. I had to go on paternity leave; hence was not deployed in all regions yet.
As soon as I'm back this will be deployed globally

@itslenny
Copy link
Contributor

itslenny commented Jun 4, 2025

This fix has been deployed to all regions and I've confirmed that it is working as expected.

One important thing to note is that you must to ensure that you are setting MetadataDirective to REPLACE in your copy command or the metadata of the original object will be preserved.

You can see more details in the AWS documentation here:
https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/MetadataDirective.html


JavaScript Example

const client = new S3Client({
  forcePathStyle: true,
  region,
  endpoint,
  credentials: {
    accessKeyId: process.env.ACCESS_KEY_ID,
    secretAccessKey: process.env.SECRET_ACCESS_KEY,
  },
})

const command = new CopyObjectCommand({
  Bucket: 'bucket-name',
  Key: 'target-file.ext',
  CopySource: 'bucket-name/source-file.ext',
  ContentType: 'audio/mp4',
  MetadataDirective: 'REPLACE'
});

const data = await client.send(command);

AWS CLI Example

aws s3api copy-object \
  --bucket bucket-name \
  --key target-file.ext \
  --copy-source bucket-name/source-file.ext \
  --content-type audio/mp4 \
  --metadata-directive REPLACE \
  --endpoint-url https://[project-ref].supabase.co/storage/v1/s3

@itslenny itslenny closed this as completed Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants