Reputation: 1674
In my web application amazon s3 is using image uploading following code is used for uploading images. But documents are not uploading using this earlier I was using same code for uploading both. Now I changed the API parameter SourceFile to Body then document is working fine but image is not in other case images working fine. I gave Body for upload documents and SourceFile for upload images. How can I use same api for both?
$result = $s3->putObject(array(
'Bucket' => Yii::app()->params['s3bucketName'],
'Key' => $fileName,
//'Body' => $fileName,
'SourceFile' => $fileName,
'ContentType' => 'text/plain',
'ACL' => 'public-read',
'StorageClass' => 'REDUCED_REDUNDANCY',
));
Upvotes: 0
Views: 212
Reputation: 6517
The Body
parameter represents the actual content of the file you are uploading. This can be a string of data or a resource created with fopen()
.
The SourceFile
parameter allows you to specify the path on disk to a file, and the SDK will take care of opening the file to retrieve and send its contents.
Which one you choose to use has nothing to do with the type of file it is.
For ContentType
, the SDK will attempt to guess the content-type of the data/file you provide, and you only need to specify it, if the content-type cannot be determined.
Upvotes: 0
Reputation: 1034
May be specifying
'ContentType' => 'text/plain',
is creating problem for image. Also for image you will need to provide SourceFile. Please check aws php sdk doc
Upvotes: 1