Classes/S3Storage.php
/**
     * Imports the given temporary file into the storage and creates the new resource object.
     *
     * @param string $temporaryPathAndFilename Path and filename leading to the temporary file
     * @param string $collectionName Name of the collection to import into
     * @return PersistentResource The imported resource
     */
Imports the given temporary file into the storage and creates the new resource object.
@param string $temporaryPathAndFilename Path and filename leading to the temporary file
@param string $collectionName Name of the collection to import into
@return PersistentResource The imported resource
Imports the given temporary file into the storage and creates the new resource object . @param string $temporaryPathAndFilename Path and filename leading to the temporary file @param string $collectionName Name of the collection to import into @return PersistentResource The imported resource
protected function importTemporaryFile(string $temporaryPathAndFilename, string $collectionName): PersistentResource
    {
        $sha1Hash = sha1_file($temporaryPathAndFilename);
        $objectName = $this->keyPrefix . $sha1Hash;
        $resource = new PersistentResource();
        $resource->setFileSize(filesize($temporaryPathAndFilename));
        $resource->setCollectionName($collectionName);
        $resource->setSha1($sha1Hash);
        try {
            $this->s3Client->headObject([
                'Bucket' => $this->bucketName,
                'Key' => $objectName
            ]);
            $objectAlreadyExists = true;
        } catch (S3Exception $e) {
            if ($e->getAwsErrorCode() !== 'NotFound') {
                throw $e;
            }
            $objectAlreadyExists = false;
        }
        if (!$objectAlreadyExists) {
            $this->s3Client->putObject([
                'Bucket' => $this->bucketName,
                'Body' => fopen($temporaryPathAndFilename, 'rb'),
                'Content-Length' => $resource->getFileSize(),
                'Content-Type' => $resource->getMediaType(),
                'Key' => $objectName
            ]);
            $this->systemLogger->info(sprintf('Successfully imported resource as object "%s" into bucket "%s" with SHA1 hash "%s"', $objectName, $this->bucketName, $resource->getSha1() ?: 'unknown'), LogEnvironment::fromMethodName(__METHOD__));
        } else {
            $this->systemLogger->info(sprintf('Did not import resource as object "%s" into bucket "%s" because that object already existed.', $objectName, $this->bucketName), LogEnvironment::fromMethodName(__METHOD__));
        }
        return $resource;
    }
protected function importTemporaryFile ( string $ temporaryPathAndFilename , string $ collectionName ) : PersistentResource { $ sha1Hash = sha1_file ( $ temporaryPathAndFilename ) ; $ objectName = $ this -> keyPrefix . $ sha1Hash ; $ resource = new PersistentResource ( ) ; $ resource -> setFileSize ( filesize ( $ temporaryPathAndFilename ) ) ; $ resource -> setCollectionName ( $ collectionName ) ; $ resource -> setSha1 ( $ sha1Hash ) ; try { $ this -> s3Client -> headObject ( [ 'Bucket' => $ this -> bucketName , 'Key' => $ objectName ] ) ; $ objectAlreadyExists = true ; } catch ( S3Exception $ e ) { if ( $ e -> getAwsErrorCode ( ) !== 'NotFound' ) { throw $ e ; } $ objectAlreadyExists = false ; } if ( ! $ objectAlreadyExists ) { $ this -> s3Client -> putObject ( [ 'Bucket' => $ this -> bucketName , 'Body' => fopen ( $ temporaryPathAndFilename , 'rb' ) , 'Content-Length' => $ resource -> getFileSize ( ) , 'Content-Type' => $ resource -> getMediaType ( ) , 'Key' => $ objectName ] ) ; $ this -> systemLogger -> info ( sprintf ( 'Successfully imported resource as object "%s" into bucket "%s" with SHA1 hash "%s"' , $ objectName , $ this -> bucketName , $ resource -> getSha1 ( ) ? : 'unknown' ) , LogEnvironment :: fromMethodName ( __METHOD__ ) ) ; } else { $ this -> systemLogger -> info ( sprintf ( 'Did not import resource as object "%s" into bucket "%s" because that object already existed.' , $ objectName , $ this -> bucketName ) , LogEnvironment :: fromMethodName ( __METHOD__ ) ) ; } return $ resource ; }
Imports the given temporary file into the storage and creates the new resource object.
Imports the given temporary file into the storage and creates the new resource object .