当前位置: 首页>>代码示例>>PHP>>正文


PHP S3Client::putObject方法代码示例

本文整理汇总了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);
 }
开发者ID:keboola,项目名称:debug-log-uploader,代码行数:14,代码来源:UploaderS3.php

示例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 . '/' : '');
 }
开发者ID:samsonphp,项目名称:fs_aws,代码行数:15,代码来源:AWSFileService.php

示例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);
 }
开发者ID:TheJester12,项目名称:s3upload_field,代码行数:7,代码来源:class.s3Facade.php

示例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);
     }
 }
开发者ID:e-ruiz,项目名称:brick,代码行数:11,代码来源:S3Storage.php

示例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);
 }
开发者ID:JoelFieldCodeProjects,项目名称:test,代码行数:14,代码来源:S3.php

示例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;
 }
开发者ID:synapsestudios,项目名称:synapse-files,代码行数:17,代码来源:S3FileService.php

示例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}''");
     }
 }
开发者ID:silktide,项目名称:stash,代码行数:9,代码来源:Version2Layer.php

示例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;
 }
开发者ID:Etheriq,项目名称:testSymfoPr,代码行数:15,代码来源:S3.php

示例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;
 }
开发者ID:kknet,项目名称:AdultMidnight,代码行数:16,代码来源:S3.php

示例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);
     }
 }
开发者ID:sanchojaf,项目名称:oldmytriptocuba,代码行数:13,代码来源:AwsS3Resolver.php

示例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;
     }
 }
开发者ID:petrabarus,项目名称:yii2-archivable-mailer,代码行数:16,代码来源:S3Provider.php

示例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');
 }
开发者ID:arsthanea,项目名称:remote-media-bundle,代码行数:14,代码来源:S3MediaUploader.php

示例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;
 }
开发者ID:inakianduaga,项目名称:eloquent-external-storage,代码行数:20,代码来源:AwsS3.php

示例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}");
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:10,代码来源:IntegrationTest.php

示例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;
 }
开发者ID:EduardoKrausME,项目名称:moodledata-to-AWS,代码行数:24,代码来源:SendS3.php


注:本文中的Aws\S3\S3Client::putObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。