當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。