问题描述
我正在编码一个视频共享站点.我正在使用S3来存储和提供视频.我已经在MySQL数据库中为视频编码了标签,但是我看到S3支持上载文件上的设置标签.这是我用来上传文件的代码:
I'm coding a video sharing site. I'm using S3 to store and serve up the videos. I've coded tags for the videos in my MySQL database but I saw that S3 supports settings tags on uploaded files. Here's the code I'm using to upload files:
try {
//Create a S3Client
$s3Client = new S3Client([
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => [
'key' => '',
'secret' => ''
]
]);
$result = $s3Client->putObject([
'Bucket' => $bucket,
'Key' => $assetFilename,
'SourceFile' => $fileTmpPath,
'Metadata' => array(
'title' => $requestAr['title'],
'description' => $requestAr['description']
)
]);
$s3Client->waitUntil('ObjectExists', array(
'Bucket' => $bucket,
'Key' => $assetFilename
));
} catch (S3Exception $e) {
returnError($e->getMessage());
}
这是一个分为两部分的问题.首先,如何在此处指定标签?我找不到任何PHP示例.接下来,假设有人上传了一个视频,然后在其上贴了标签. S3标签是键/值对.我应该为按键设置什么?我当时想为每个视频使用[tag1,tag2,tag3]之类的东西,这些值就是标签字符串.这是S3标签文档: https://docs.aws. amazon.com/AmazonS3/latest/dev/object-tagging.html
This is a 2 part question. First, how can I specify tags here? I can't find any PHP examples. Next, let's say someone uploads a video and they put a tag on it. S3 tags are key/value pairs. What should I set for the keys? I was thinking of just using something like [tag1, tag2, tag3] for each video and the value of those being the tag strings. Here's the S3 tags doc: https://docs.aws.amazon.com/AmazonS3/latest/dev/object-tagging.html
推荐答案
要设置对象标签,只需将Tagging
元素传递给putObject()
参数.就您而言,就像这样:
To set an object tag, simply pass the Tagging
element to the putObject()
parameters. In your case, it'd be like this:
$result = $s3Client->putObject([
'Bucket' => $bucket,
'Key' => $assetFilename,
'SourceFile' => $fileTmpPath,
'Tagging' => 'category=tag1', // your tag here!
'Metadata' => array(
'title' => $requestAr['title'],
'description' => $requestAr['description']
)
]);
请注意,标记是一个简单的key=value
字符串.作为前瞻性思考"措施,我将标记设为category=tagValue
,以便您可以对其进行分类并最终添加更多标记类别.如果您执行tag1=true
,它将很快变得混乱.
Notice the tag is a simple key=value
string. As a "thinking ahead" measure, I'd make the tags be category=tagValue
, so you can categorize them and eventually add more tag categories. If you do tag1=true
, then it'll get messy quick.
这篇关于PHP Amazon S3上传和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!