Skip to content
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

How to Add x-amz-meta-<key> = "<value>" To S3 Bucket Object Metadata #472

Open
jaradc opened this issue Nov 20, 2021 · 1 comment
Open

Comments

@jaradc
Copy link

jaradc commented Nov 20, 2021

image

I'm new to EvaporateJS. I came across it because I'm using django-s3direct. Please see that link. I'm literally using that code unmodified as it is.

What Am I Trying To Do?

I want to attach metadata to the S3 uploaded file and I want to see that metadata on the object when I view it within the S3 interface (like in my image above).

What Have I Tried?

I Learned from issue #428 that Evaporate.prototype.add() is where I should define metadata.

In the django-s3direct code, I see this:

const addConfig = {
		name: uploadParameters.object_key,
		file: file,
		contentType: file.type,
		xAmzHeadersCommon: generateAmzCommonHeaders(uploadParameters.session_token),
		xAmzHeadersAtInitiate: generateAmzInitHeaders(
			uploadParameters.acl,
			uploadParameters.server_side_encryption,
			uploadParameters.session_token
		),
		progress: (progressRatio, stats) => {
			updateProgressBar(element, progressRatio);
		},
		warn: (warnType, area, msg) => {
			if (msg.includes('InvalidAccessKeyId')) {
				error(element, msg);
			}
		}
	};

I have tried adding the following, but I still don't see any metadata appear on my uploaded S3 object.

Tried to add header x-amz-meta-abc in the generateAmzCommonHeaders part (which defines xAmzHeadersCommon):

const generateAmzCommonHeaders = sessionToken => {
	const headers = {};
	if (sessionToken) headers['x-amz-security-token'] = sessionToken;
	headers['x-amz-meta-abc'] = '123'; // <--- tried this
	return headers;
};

Tried to add header x-amz-meta-abc in generateAmzInitHeaders const (which defines xAmzHeadersAtInitiate):

const generateAmzInitHeaders = (acl, serverSideEncryption, sessionToken) => {
	const headers = {};
	if (acl) headers['x-amz-acl'] = acl;
	if (sessionToken) headers['x-amz-security-token'] = sessionToken;
	if (serverSideEncryption) {
		headers['x-amz-server-side-encryption'] = serverSideEncryption;
	}
	headers['x-amz-meta-abc'] = '123'; // <--- tried this
	return headers;
};

Adding to notSignedHeadersAtInitiate:

	const optHeaders = {};
	optHeaders['x-amz-meta-abc'] = '123';
        ...
	addConfig['notSignedHeadersAtInitiate'] = optHeaders;

Both versions of xAmzHeadersAtUpload and xAmzHeadersAtComplete:

	const addConfig = {
		name: uploadParameters.object_key,
		file: file,
		contentType: file.type,
		xAmzHeadersCommon: generateAmzCommonHeaders(uploadParameters.session_token),
		xAmzHeadersAtInitiate: generateAmzInitHeaders(
			uploadParameters.acl,
			uploadParameters.server_side_encryption,
			uploadParameters.session_token
		),
		xAmzHeadersAtUpload: {'x-amz-meta-abc': '123'}, // <-- tried this
		xAmzHeadersAtComplete: {'x-amz-meta-abc': '123'}, // <-- tried this
		progress: (progressRatio, stats) => {
			updateProgressBar(element, progressRatio);
		},
		warn: (warnType, area, msg) => {
			if (msg.includes('InvalidAccessKeyId')) {
				error(element, msg);
			}
		}
	};

What am I'm doing wrong? Is it a CORS or bucket config? Is it my code or approach / understanding?

@jaradc jaradc changed the title How to Add x-amz-meta-<whatever> = "whatever" TO S3 Bucket How to Add x-amz-meta-<whatever> = "whatever" To S3 Bucket Object Metadata Nov 20, 2021
@jaradc jaradc changed the title How to Add x-amz-meta-<whatever> = "whatever" To S3 Bucket Object Metadata How to Add x-amz-meta-<key> = "<value>" To S3 Bucket Object Metadata Nov 20, 2021
@stri8ed
Copy link

stri8ed commented Jan 6, 2024

use this:

 xAmzHeadersAtInitiate: {
    'x-amz-meta-custom-meta-key': 'CustomMetaDataValue'
}

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

No branches or pull requests

2 participants