本文整理汇总了PHP中Aws\S3\S3Client::putObject方法的典型用法代码示例。如果您正苦于以下问题:PHP S3Client::putObject方法的具体用法?PHP S3Client::putObject怎么用?PHP S3Client::putObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\S3\S3Client
的用法示例。
在下文中一共展示了S3Client::putObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadString
/**
* Uploads string as file to s3
* @param $name
* @param $content
* @param string $contentType
* @return string
*/
public function uploadString($name, $content, $contentType = 'text/plain')
{
$s3FileName = $this->getFilePathAndUniquePrefix() . $name;
list($bucket, $prefix) = explode('/', $this->s3path, 2);
$this->s3client->putObject(['Bucket' => $bucket, 'Key' => (empty($prefix) ? '' : trim($prefix, '/') . '/') . $s3FileName, 'ContentType' => $contentType, 'ACL' => 'private', 'ServerSideEncryption' => 'AES256', 'Body' => $content]);
return $this->withUrlPrefix($s3FileName);
}
示例2: write
/**
* Write data to a specific relative location
*
* @param mixed $data Data to be written
* @param string $filename File name
* @param string $uploadDir Relative file path
* @return string Relative path to created file, false if there were errors
*/
public function write($data, $filename = '', $uploadDir = '')
{
// Upload data to Amazon S3
$this->client->putObject(array('Bucket' => $this->bucket, 'Key' => $uploadDir . '/' . $filename, 'Body' => $data, 'CacheControl' => 'max-age=' . $this->maxAge, 'ACL' => 'public-read'));
// Build absolute path to uploaded resource
return $this->bucketURL . '/' . (isset($uploadDir[0]) ? $uploadDir . '/' : '');
}
示例3: putObject
public function putObject($bucket, $key, $filePath, $options)
{
$options['Bucket'] = $bucket;
$options['Key'] = $key;
$options['Body'] = EntityBody::factory(fopen($filePath, 'r+'));
return $this->s3->putObject($options);
}
示例4: put
/**
* {@inheritdoc}
*/
public function put($path, $data)
{
try {
$this->s3->putObject(['Bucket' => $this->bucket, 'Key' => $path, 'Body' => $data]);
} catch (AwsExceptionInterface $e) {
throw Exception\StorageException::putError($path, $e);
}
}
示例5: move
/**
* Move an uploaded file to it's intended destination.
*
* @param string $file
* @param string $filePath
*/
public function move($file, $filePath)
{
$objectConfig = $this->attachedFile->s3_object_config;
$fileSpecificConfig = ['Key' => $filePath, 'SourceFile' => $file, 'ContentType' => $this->attachedFile->contentType()];
$mergedConfig = array_merge($objectConfig, $fileSpecificConfig);
$this->ensureBucketExists($mergedConfig['Bucket']);
$this->s3Client->putObject($mergedConfig);
}
示例6: save
/**
* @param string $path
* @param string|resource $data
* @param string $contentType
*
* @return bool
* @throws FileException
*/
public function save($path, $data, $contentType = null)
{
try {
$this->s3->putObject(['Bucket' => $this->bucket, 'Key' => $path, 'Body' => $data, 'ContentType' => $contentType]);
} catch (\Exception $e) {
throw new FileException('Unable to save file', $e->getCode(), $e);
}
return true;
}
示例7: set
public function set($key, $value, $ttl = null)
{
$this->load();
try {
$this->s3Client->putObject(["Bucket" => S3Cache::BUCKET, "Key" => $key, "Body" => $value, "Expires" => $this->ttlToDateTime($ttl, $this->defaultTTL)]);
} catch (\Exception $e) {
throw new \RuntimeException("Unable to set object in S3Cache '{$key}''");
}
}
示例8: upload
/**
* @param $filename
* @param $filePath
* @param string $mimeType
* @return \Aws\Result|null
*/
public function upload($filename, $filePath, $mimeType = 'image/jpeg')
{
$result = null;
try {
$result = $this->s3->putObject(['Bucket' => $this->bucket, 'Key' => $filename, 'SourceFile' => $filePath, 'ACL' => self::ACL_PRIVATE_READ, 'ContentType' => $mimeType]);
} catch (\Exception $e) {
}
return $result;
}
示例9: upload
/**
* S3の指定パスへファイルをアップロードする
*
* @param string $from_path
* @param string $to_path
* @return void
**/
public function upload($from_path, $to_path)
{
try {
$this->client->putObject(array('Bucket' => $this->bucket, 'Key' => $to_path, 'Body' => EntityBody::factory(fopen($from_path, 'r'))));
} catch (\Exception $e) {
throw $e;
}
return true;
}
示例10: store
/**
* {@inheritDoc}
*/
public function store(BinaryInterface $binary, $path, $filter)
{
$objectPath = $this->getObjectPath($path, $filter);
try {
$this->storage->putObject(array('ACL' => $this->acl, 'Bucket' => $this->bucket, 'Key' => $objectPath, 'Body' => $binary->getContent(), 'ContentType' => $binary->getMimeType()));
} catch (\Exception $e) {
$this->logError('The object could not be created on Amazon S3.', array('objectPath' => $objectPath, 'filter' => $filter, 'bucket' => $this->bucket, 'exception' => $e));
throw new NotStorableException('The object could not be created on Amazon S3.', null, $e);
}
}
示例11: uploadHtml
/**
* @param string $html the content to be uploaded.
* @return string the URL of the uploaded content.
*/
public function uploadHtml($headers, $html)
{
$file = date('YmdHis-') . uniqid("", true);
$key = (!empty($this->directoryPath) ? $this->directoryPath . '/' : '') . $file . '.html';
$url = $this->_client->getObjectUrl($this->bucket, $key);
$result = $this->_client->putObject(array_merge(['ACL' => 'public-read', 'Bucket' => $this->bucket, 'Body' => str_replace($this->archiveUrlTag, $url, $html), 'CacheControl' => 'max-age=31536000, public', 'ContentType' => 'text/html', 'Key' => $key, 'Metadata' => ['X-UID-MailHeader' => \yii\helpers\Json::encode($headers)], 'Expires' => gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime('+5 year'))], $this->uploadOptions));
if ($result) {
return $url;
} else {
return false;
}
}
示例12: uploadMedia
public function uploadMedia(Media $media, $acl = 'public-read')
{
$targetPath = parse_url($media->getUrl(), PHP_URL_PATH);
if ($media->getUrl() === $targetPath) {
throw new \InvalidArgumentException('Media has to have a public URL set before uploading');
}
if (null === $media->getContent()) {
throw new \RuntimeException('Dunno how to get file contents');
}
$fd = fopen($media->getContent()->getRealPath(), 'rb');
$storageResponse = $this->storage->putObject(['ACL' => $acl, 'Bucket' => $this->bucketName, 'Key' => ltrim($targetPath, '/'), 'Body' => $fd, 'ContentType' => $media->getContentType(), 'CacheControl' => 'public, max-age=283824000', 'Expires' => gmdate('D, d M Y H:i:s T', strtotime('+9 years'))]);
fclose($fd);
return $storageResponse->get('ObjectURL');
}
示例13: store
/**
* {@inheritDoc}
*
* @link http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpPHP.html
*/
public function store($content)
{
$relativePath = $this->generateStoragePath($content);
$absolutePath = $this->getConfigRelativeKey('s3BucketSubfolder') . '/' . $relativePath;
// Note: The S3 doesS3ObjectExist method has a problem when the object doesn't exist within the sdk, so we skip this check for now
// if(! $this->doesS3ObjectExist($this->getConfigRelativeKey('s3Bucket'),, $absolutePath)) {
try {
$this->s3->putObject(array('Bucket' => $this->getConfigRelativeKey('s3Bucket'), 'Key' => $absolutePath, 'Body' => $content));
} catch (S3Exception $e) {
echo "There was an error uploading the file: " . $e->getMessage() . PHP_EOL;
$absolutePath = false;
}
// }
return $absolutePath;
}
示例14: testPutObjectsWithUtf8Keys
/**
* @depends testPutAndListObjects
*/
public function testPutObjectsWithUtf8Keys()
{
self::log("Uploading an object with a UTF-8 key");
$key = 'åbc';
$this->client->putObject(array('Bucket' => $this->bucket, 'Key' => $key, 'Body' => 'hi'));
$this->client->waitUntil('object_exists', "{$this->bucket}/{$key}");
}
示例15: send
/**
* @param string $file_filename
* @param string $fileDe
* @param string $filePara
* @param string $file_mimetype
* @param string $acl
* @return \Guzzle\Service\Resource\Model
*/
public function send($file_filename, $fileDe, $filePara, $file_mimetype = null, $acl = \Aws\S3\Enum\CannedAcl::PUBLIC_READ)
{
if ($file_mimetype == null) {
$file_mimetype = $this->getMimeType($file_filename);
}
$filePara = str_replace('/_s/', '/', $filePara);
if (!class_exists('S3Util')) {
require_once __DIR__ . '/S3Util.php';
}
$sendObject = array('Bucket' => $this->bucket_name, 'SourceFile' => $fileDe, 'Key' => S3Util::getPrefix() . $filePara, 'ACL' => $acl, 'CacheControl' => 'max-age=1296000', 'Expires' => date('r', mktime(0, 0, 0, date('m'), date('d'), date('Y') + 10)), 'Etag' => md5($filePara), 'ContentType' => $file_mimetype, 'StorageClass' => \Aws\S3\Enum\StorageClass::STANDARD, 'ContentDisposition' => 'filename="' . $file_filename . '"');
try {
return $this->client->putObject($sendObject);
} catch (Exception $e) {
}
return null;
}