mercredi 29 avril 2015

Using headObject to get x-amz-meta from S3 File

I have a file on S3 with some metadata for example x-amz-meta-description="some description" This metadata was included when I uploaded the file to S3. If I use Amazon console to check the metadata, the metadata is there. Next, I added the following to the CORS configuration to have access to the headers:

<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>HEAD</AllowedMethod>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>

From my web app, I'm trying to check the headers of my file. I'm using the following javascript code:

AWS.config.update({accessKeyId: 'XXX', secretAccessKey: 'YYY'})
var bucket = new AWS.S3({params: {Bucket: 'zzz'}});
var params = {Bucket: 'zzz',Key: 'content/myfile.doc'};
bucket.headObject(params, function (err, data) {
    if (err)
        console.log(err, err.stack);
    else
        console.log(data);
});

After running the code data.Metadata is empty. Is there any other configuration to get the metadata associated to the file? What am I doing wrong?

Thanks for all

PS:I used getObject function, but Metadata is still empty.




Aucun commentaire:

Enregistrer un commentaire