Scalr\Service\Aws\S3\V20060301\S3Api::addObject PHP Method

addObject() public method

This implementation of the PUT operation adds an object to a bucket.You must have WRITE permissions on a bucket to add an object to it.
public addObject ( string $bucketName, string $objectName, string | SplFileInfo $contentFile, array $requestHeaders = null ) : Scalr\Service\Aws\Client\ClientResponseInterface
$bucketName string A bucket name.
$objectName string An object name.
$contentFile string | SplFileInfo File content of file that should be uploaded. If you provide a path to the file you should pass SplFileInfo object.
$requestHeaders array optional Request headers
return Scalr\Service\Aws\Client\ClientResponseInterface Returns response on success or throws an exception
    public function addObject($bucketName, $objectName, $contentFile, array $requestHeaders = null)
    {
        $options = array('_subdomain' => (string) $bucketName);
        $allowedRequestHeaders = array('Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-Length', 'Content-MD5', 'Content-Type', 'Expect', 'Expires', 'x-amz-meta-', 'x-amz-server-side-encryption', 'x-amz-storage-class', 'x-amz-website-redirect-location');
        if (!empty($requestHeaders)) {
            $requestHeaders = $this->getFilteredArray(array_merge($allowedRequestHeaders, self::$xamzAclAllowedHeaders), $requestHeaders);
            $options = array_merge($options, $requestHeaders);
        }
        if ($contentFile instanceof \SplFileInfo) {
            if (!$contentFile->isFile()) {
                throw new S3Exception(sprintf('File "%s" does not exist', $contentFile->getPathname()));
            }
            $options['_putFile'] = $contentFile->getPathname();
        } else {
            $options['_putData'] = $contentFile;
        }
        $response = $this->client->call('PUT', $options, sprintf('/%s', self::escapeObjectName($objectName)));
        return $response->getError() ?: $response;
    }