本文介绍了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).因此,所有路径/目录信息都必须是密钥"的一部分.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 13:10