PutObject 到目录 Amazon s3/PHP [英] PutObject into directory Amazon s3 / PHP

查看:48
本文介绍了PutObject 到目录 Amazon s3/PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将我的文件上传到我在 amazon s3 存储上创建的特定目录中.我总是将文件上传到我的存储桶的绝对路径"上,执行如下操作:

I need to upload my files inside specific directories that I created on my amazon s3 storage. I always uploaded the files on the "absolute path" of my bucket doing something like so:

$s3->putObject(array(
            'Bucket' => $bucket,
            'ContentType'   => $mime,
            'Key'           => $localImage,
            'ACL'           => 'public-read',
            'SourceFile'    => $localImage,
            'CacheControl'  => 'max-age=172800',
            "Expires"       => gmdate("D, d M Y H:i:s T", strtotime("+5 years")),
            'Metadata'      => array(
                'profile' => $localImage,
            ),
        )); 

如何定义此文件应上传到给定目录的何处?

How can I define where this file should be uploaded on a given directory?

推荐答案

您必须在Key"参数中包含该信息.S3 实际上不是一个文件系统,它更像是一个大(哈希表)关联数组.Bucket"是哈希表的名称,Key"是键(例如,$bucket[$key] = $content).所以所有的路径/目录信息都必须是Key"的一部分.

You must include that information in the "Key" parameter. S3 isn't actually a filesystem, it's more like a big (hash table) associative array. The "Bucket" is the name of the hash table, and the "Key" is the key (e.g., $bucket[$key] = $content). So all path/directory information must be a part of the "Key".

$localImage = '/Users/jim/Photos/summer-vacation/DP00342654.jpg';
$s3->putObject(array(
    'Bucket'     => 'my-uniquely-named-bucket',
    'SourceFile' => $localImage,
    'Key'        => 'photos/summer/' . basename($localImage)
));

这篇关于PutObject 到目录 Amazon s3/PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆