简体   繁体   English

SourceFile Amazon AWS S3

[英]SourceFile Amazon AWS S3

I'm trying to upload a file to my bucket. 我正在尝试将文件上传到存储桶。 I am able to upload with Body but not SourceFile. 我可以使用Body而不是SourceFile上传。 Here's my method: 这是我的方法:

$pathToFile='/explicit/path/to/file.jpg'

// Upload an object by streaming the contents of a file
$result = $s3Client->putObject(array(
            'Bucket'     => $bucket,
            'Key'        => 'test.jpg',
            'SourceFile'   => $pathToFile,
            'ACL'    => 'public-read',
            'ContentType' => 'image/jpeg'
));

but I get this error: 但是我得到这个错误:

You must specify a non-null value for the Body or SourceFile parameters.

I've tried different types of files and keep getting this error. 我尝试了不同类型的文件,并不断收到此错误。

The issue had to do with not giving a good path. 这个问题与没有给出好的路径有关。 Looks like file_exists() only checks locally, meaning that it had to be within localhost's index. 看起来file_exists()仅在本地检查,这意味着它必须在localhost的索引内。

Change 更改

'SourceFile'   => $pathToFile,

to

'Body'   => $pathToFile,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM