DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Managing AWS Managed Microsoft Active Directory Objects With AWS Lambda Functions
  • Configuring Amazon S3 Using Mulesoft
  • S3-Compatible Object Storage Powered by Blockchain/Web3
  • Building an AWS Integration for Salesforce Image Handling

Trending

  • How to Format Articles for DZone
  • Unlocking Data with Language: Real-World Applications of Text-to-SQL Interfaces
  • Blue Skies Ahead: An AI Case Study on LLM Use for a Graph Theory Related Application
  • How Clojure Shapes Teams and Products
  1. DZone
  2. Data Engineering
  3. Databases
  4. How To: Set and Retrieve Metadata of an S3 Object

How To: Set and Retrieve Metadata of an S3 Object

By 
Vijaykishan Shyamsundar user avatar
Vijaykishan Shyamsundar
·
Jan. 14, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
32.6K Views

Join the DZone community and get the full member experience.

Join For Free

In the article we will see how to upload the metadata of an object while uploading to S3 programatically.

I will be using Node.js to demonstrate the same.

Before jumping to that let’s see what is metadata and it’s use case

We have 2 types of metadata

  1. System Metadata    E.g. Date, Content-Length
  2. User defined metadata

While we upload the object, we can add custom metadata about the object along that as a key-value pair

 

Note: All user-defined metadata keys in lowercase

 

Let’s say we are having a platform where contents are added by multiple organization. In this scenario adding OrganizationID as one of the metadata will be handy.

Following code helps you to upload an object to s3 along it’s metadata.

JavaScript




x
43


 
1
var AWS = require('aws-sdk')
2
var credentials = require('./cred');
3
var s3 = new AWS.S3({accessKeyId: credentials.accesskey,
4
    secretAccessKey: credentials.secretkey,region:credentials.region});
5
var fs = require('fs');
6
 
          
7
fs.readFile('file2.txt', function (err, data) {
8
    if (err) { throw err; }
9
    var base64data = new Buffer(data, 'binary');
10
    s3.putObject({
11
        Bucket: 'uploadmetatest',
12
        Key: 'vijaykishan.txt',
13
        Metadata: {OrgID: 'TEKKIHUT', PROFILE: 'HD'},
14
        Body: base64data,
15
        ACL: 'public-read'
16
    }, function (resp) {
17
        console.log('Successfully uploaded package.');
18
    });
19
});


 

Let’s see how to retrieve the metadata of an uploaded object using node.js.

Following code helps you to retrieve the metadata of an object uploaded to s3.

JavaScript
xxxxxxxxxx
1
25
 
1
var params = {
2
    Bucket: "uploadmetatest",
3
    Key: "file2.txt"
4
};
5
s3.headObject(params, function (err, data) {    if (err) console.log(err, err.stack); // an error occurred
6
    else {
7
        console.log(data.Metadata['orgid']);
8
        console.log(data.Metadata['profile']);
9
   }       
10
});

 

Note

The PUT request header is limited to 8 KB in size. Within the PUT request header, the user-defined metadata is limited to 2 KB in size. The size of user-defined metadata is measured by taking the sum of the number of bytes in the UTF-8 encoding of each key and value.

 

Hope this helps

Metadata AWS Object (computer science)

Opinions expressed by DZone contributors are their own.

Related

  • Managing AWS Managed Microsoft Active Directory Objects With AWS Lambda Functions
  • Configuring Amazon S3 Using Mulesoft
  • S3-Compatible Object Storage Powered by Blockchain/Web3
  • Building an AWS Integration for Salesforce Image Handling

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!