Пример #1
9
 /**
  * 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 Resource The imported resource
  */
 protected function importTemporaryFile($temporaryPathAndFilename, $collectionName)
 {
     $sha1Hash = sha1_file($temporaryPathAndFilename);
     $md5Hash = md5_file($temporaryPathAndFilename);
     $resource = new Resource();
     $resource->setFileSize(filesize($temporaryPathAndFilename));
     $resource->setCollectionName($collectionName);
     $resource->setSha1($sha1Hash);
     $resource->setMd5($md5Hash);
     $objectName = $this->keyPrefix . $sha1Hash;
     $options = array('Bucket' => $this->bucketName, 'Body' => fopen($temporaryPathAndFilename, 'rb'), 'ContentLength' => $resource->getFileSize(), 'ContentType' => $resource->getMediaType(), 'Key' => $objectName);
     if (!$this->s3Client->doesObjectExist($this->bucketName, $this->keyPrefix . $sha1Hash)) {
         $this->s3Client->putObject($options);
         $this->systemLogger->log(sprintf('Successfully imported resource as object "%s" into bucket "%s" with MD5 hash "%s"', $objectName, $this->bucketName, $resource->getMd5() ?: 'unknown'), LOG_INFO);
     } else {
         $this->systemLogger->log(sprintf('Did not import resource as object "%s" into bucket "%s" because that object already existed.', $objectName, $this->bucketName), LOG_INFO);
     }
     return $resource;
 }
Пример #2
0
 /**
  * Check whether a file exists.
  *
  * @param string $path
  *
  * @return bool
  */
 public function has($path)
 {
     $location = $this->applyPathPrefix($path);
     if ($this->s3Client->doesObjectExist($this->bucket, $location)) {
         return true;
     }
     return $this->doesDirectoryExist($location);
 }
Пример #3
0
 /**
  * Check if a blob exists
  *
  * @param  string $container Container name
  * @param  string $name      Blob name
  *
  * @return boolean
  */
 public function blobExists($container = '', $name = '')
 {
     try {
         $this->checkConnection();
         return $this->blobConn->doesObjectExist($container, $name);
     } catch (\Exception $ex) {
         return false;
     }
 }
Пример #4
0
 /**
  * Checks if a file exists on the DFS
  *
  * @param string $filePath
  *
  * @return bool
  */
 public function existsOnDFS($filePath)
 {
     try {
         return $this->s3client->doesObjectExist($this->bucket, $filePath);
     } catch (S3Exception $e) {
         eZDebug::writeError($e->getMessage(), __METHOD__);
         return false;
     }
 }
Пример #5
0
 /**
  * Return whether a file exists.
  *
  * @param  string            $file
  * @return boolean           Whether the file exists
  * @throws \RuntimeException
  */
 public function exists($file)
 {
     if (null !== $this->filenameFilter) {
         $file = $this->filenameFilter->filter($file);
     }
     try {
         return $this->s3Client->doesObjectExist($this->getBucket(), $file);
     } catch (S3Exception $e) {
         if (!$this->getThrowExceptions()) {
             return false;
         }
         throw new \RuntimeException('Exception thrown by Aws\\S3\\S3Client: ' . $e->getMessage(), null, $e);
     }
 }
Пример #6
0
 public function filetype($path)
 {
     $path = $this->normalizePath($path);
     try {
         if ($path != '.' && $this->connection->doesObjectExist($this->bucket, $path)) {
             return 'file';
         }
         if ($path != '.') {
             $path .= '/';
         }
         if ($this->connection->doesObjectExist($this->bucket, $this->cleanKey($path))) {
             return 'dir';
         }
     } catch (S3Exception $e) {
         \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
     return false;
 }
Пример #7
0
 protected function saveImage(array $file, $subdirectory = '')
 {
     $s3 = new S3Client(['version' => 'latest', 'region' => 'eu-west-1']);
     $subdirectory = trim($subdirectory, '/');
     list($name, $extension) = explode('.', trim($file['name'], '/'));
     $filename = md5((string) rand()) . '.' . $extension;
     $directory = self::$public_image_directory . '/' . $subdirectory . '/';
     $bucket_name = 'comp3013';
     if (!$s3->doesBucketExist($bucket_name)) {
         echo 'Error, bucket didnt exist';
         exit(0);
     }
     while ($s3->doesObjectExist($bucket_name, $directory . $filename)) {
         $filename = md5((string) rand()) . '.' . $extension;
     }
     $parameters = ['ContentType' => $file['type'], 'Bucket' => $bucket_name, 'Key' => $directory . $filename, 'SourceFile' => $file['tmp_name']];
     print_r($parameters);
     $s3->putObject($parameters);
     $s3->waitUntil('ObjectExists', ['Bucket' => $bucket_name, 'Key' => $directory . $filename]);
     //exit(0);
     return 'http://comp3013.s3-website-eu-west-1.amazonaws.com/' . $directory . $filename;
 }
Пример #8
0
 /**
  * If path is diretory
  *
  * @param string $path Remote folder
  *
  * @return bool
  */
 public function isDir($path)
 {
     $path = trim($path, '/') . '/';
     return $this->clientS3->doesObjectExist($this->bucket, $path);
 }
Пример #9
0
 /**
  * Checks whether an object exists.
  *
  * @param string $objectPath
  *
  * @return bool
  */
 protected function objectExists($objectPath)
 {
     return $this->storage->doesObjectExist($this->bucket, $objectPath);
 }
Пример #10
0
 public function exists($key)
 {
     $this->load();
     return $this->s3Client->doesObjectExist(S3Cache::BUCKET, $key);
 }
 /**
  * _removeFileFromS3
  *
  * @param string $file Path of the file
  * @param \Cake\ORM\Entity $entity Entity to check on.
  * @param string $field Field to check on.
  * @return bool
  */
 protected function _removeFileFromS3($file, $entity, $field)
 {
     if ($file != null && $file != '') {
         // Only if a file exist!
         $bucketName = $this->_getBucketName($this->_customerSite, $field);
         if ($this->_s3Client->doesObjectExist($bucketName, $file)) {
             $result = $this->_s3Client->deleteObject(array('Bucket' => $bucketName, 'Key' => $file));
         }
     }
     //TODO: migliorare il ritorno
     return true;
 }
Пример #12
0
 /**
  * Determines whether or not an object exists by name
  *
  * @param string $bucket The name of the bucket
  * @param string $key The key of the object
  * @param array  $params Additional options to add to the executed command
  *
  * @return bool
  */
 public function doesObjectExist($bucket, $key, array $params = [])
 {
     return $this->instance->doesObjectExist($bucket, $key, $params);
 }
Пример #13
0
 /**
  * 指定パスのファイルがS3にあるかどうかを判別する
  *
  * @param  string $path
  * @return boolean
  **/
 public function doesObjectExist($path)
 {
     return $this->client->doesObjectExist($this->bucket, $path);
 }
Пример #14
0
 /**
  * Check existing current file in current file system
  * @param $url string Url
  * @return boolean File exists or not
  */
 public function exists($url)
 {
     // Get file key name on amazon s3
     $fileKey = str_replace($this->bucketURL, '', $url);
     return $this->client->doesObjectExist($this->bucket, $fileKey);
 }
Пример #15
0
 /**
  * Asks the driver if it has a particular file.
  *
  * @param FileModel $fileModel
  * @param array $options
  * @return bool
  */
 public function has(FileModel $fileModel, array $options = [])
 {
     // Check if file exists
     return $this->s3->doesObjectExist($this->awsBucket, $this->nameGenerator->fileName($fileModel, $options));
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function has($path)
 {
     return $this->s3->doesObjectExist($this->bucket, $path);
 }
 public function exists(Media $media)
 {
     return $this->storage->doesObjectExist($this->bucketName, ltrim(parse_url($media->getUrl(), PHP_URL_PATH), '/'));
 }
Пример #18
0
$s3 = new S3Client(['version' => S3_VERSION, 'region' => S3_REGION]);
$message = "";
if (!empty($_POST['submit'])) {
    if (!empty($_FILES["uploadfile"])) {
        $filename = $_FILES["uploadfile"]["name"];
        $file = $_FILES["uploadfile"]["tmp_name"];
        $filetype = $_FILES["uploadfile"]["type"];
        $filesize = $_FILES["uploadfile"]["size"];
        $filedata = file_get_contents($file);
        $bucket = $_POST['bucket'];
        // insert into redis use base64
        $base64 = base64_encode(file_get_contents($file));
        $filekey = $filename . DATA_SEPARATOR . $filetype . DATA_SEPARATOR . $filesize . DATA_SEPARATOR . time() . DATA_SEPARATOR . $bucket;
        $redis->mset($filekey, $base64);
        // create or update imagelist.txt
        if ($s3->doesObjectExist(S3_BUCKET, IMAGELIST_FILE)) {
            // exsist
            $txtfile = $s3->getObject(['Bucket' => S3_BUCKET, 'Key' => IMAGELIST_FILE]);
            $txtbody = $txtfile['Body'] . $filekey . PHP_EOL;
            try {
                $s3->deleteObject(['Bucket' => S3_BUCKET, 'Key' => IMAGELIST_FILE]);
                $s3->putObject(['Bucket' => S3_BUCKET, 'Key' => IMAGELIST_FILE, 'Body' => $txtbody, 'ACL' => 'public-read-write']);
            } catch (Aws\Exception\S3Exception $e) {
                $message .= "There was an error deleting and creating imagelist.txt.\r\n";
            }
        } else {
            // create imagelist.txt
            try {
                $s3->putObject(['Bucket' => S3_BUCKET, 'Key' => IMAGELIST_FILE, 'Body' => $filekey . PHP_EOL, 'ACL' => 'public-read-write']);
            } catch (Aws\Exception\S3Exception $e) {
                $message .= "There was an error creating imagelist.txt.\r\n";
Пример #19
0
 /**
  * objectExist
  *
  * @param string $key
  * @param array  $options
  *
  * @return boolean
  */
 public function objectExist($key, array $options = array())
 {
     return $this->client->doesObjectExist($this->name, $key, $options);
 }
        	<?php 
}
?>
   	   
    	    <table class="table">
                <tr>
                    <th>Bucket</th>
                    <th>File Name</th>
                    <th>Download Link</th>
                    <th>Resized Image</th>
                </tr>
            <?php 
$result = $s3->listBuckets();
foreach ($result['Buckets'] as $bucket) {
    // Each Bucket value will contain a Name and CreationDate
    if ($s3->doesObjectExist($bucket['Name'], SMALLIMAGELIST_FILE)) {
        $txtfile = $s3->getObject(['Bucket' => $bucket['Name'], 'Key' => SMALLIMAGELIST_FILE]);
        $txtbody = $txtfile['Body'];
        $lines = explode(PHP_EOL, $txtbody);
        foreach ($lines as $key) {
            if (trim($key) != '') {
                $tag = preg_split("/######/", $key);
                echo '<tr>';
                echo '<td>' . $bucket['Name'] . '</td>';
                echo '<td>' . $tag[1] . '</td>';
                echo '<td><a href="' . S3_PATH . $bucket['Name'] . '/' . $tag[1] . '">Click</a></td>';
                echo '<td><a href="' . S3_PATH . $bucket['Name'] . '/' . $tag[2] . '"><img src="' . S3_PATH . $bucket['Name'] . '/' . $tag[2] . '"/></a></td>';
                echo '</tr>';
            }
        }
    }
Пример #21
0
 /**
  * Check wether a file exists
  *
  * @param   string  $path
  * @return  bool    weather an object result
  */
 public function has($path)
 {
     return $this->client->doesObjectExist($this->bucket, $this->prefix($path));
 }
Пример #22
0
 /**
  * Asks the driver if it has a particular image.
  *
  * @param \TippingCanoe\Imager\Model\Image $image
  * @param array $filters
  * @return boolean
  */
 public function has(Image $image, array $filters = [])
 {
     // Check if file exists
     return $this->s3->doesObjectExist($this->awsBucket, $this->generateFileName($image, $filters));
 }
 /**
  * Check whether a file exists.
  *
  * @param string $path
  *
  * @return bool
  */
 public function has($path)
 {
     $location = $this->applyPathPrefix($path);
     return $this->s3Client->doesObjectExist($this->bucket, $location);
 }
Пример #24
0
 public function beforeDelete()
 {
     $photos = VideoScreens::find()->where(['video_id' => $this->id])->all();
     foreach ($photos as $photo) {
         if (file_exists("../web" . $photo->screen_url)) {
             unlink("../web" . $photo->screen_url);
         }
     }
     $config = ArrayHelper::map(Config::find()->all(), 'name', 'value');
     if ($this->storage == 2) {
         $s3 = new S3Client(['version' => 'latest', 'region' => 'us-west-2', 'credentials' => ['key' => $config['amazon_key'], 'secret' => $config['amazon_secret']]]);
         try {
             for ($i = 0; $i < 3; $i++) {
                 $field = "object_url_" . $i;
                 if (!empty($this->{$field})) {
                     if ($s3->doesObjectExist($config['amazon_bucket'], 'video/' . urldecode(mb_substr($this->{$field}, mb_strrpos($this->{$field}, '/') + 1)))) {
                         $res = $s3->deleteObject(['Bucket' => $config['amazon_bucket'], 'Key' => 'video/' . urldecode(mb_substr($this->{$field}, mb_strrpos($this->{$field}, '/') + 1))]);
                     }
                 }
             }
         } catch (S3Exception $e) {
             echo $e->getMessage();
             Yii::$app->session->setFlash('error', $e->getMessage());
         }
     } else {
         if ($this->storage == 1) {
             for ($i = 0; $i < 3; $i++) {
                 $field = "object_url_" . $i;
                 if (!empty($this->{$field}) && file_exists("../web" . $this->{$field})) {
                     unlink("../web" . $this->{$field});
                 }
             }
         } else {
             for ($i = 0; $i < 3; $i++) {
                 $field = "object_url_" . $i;
                 $arr = explode('/', $this->{$field});
                 $f = array_pop($arr);
                 //echo $f;
                 //die();
                 // $f = '14529312860.mp4';
                 $this->ftp_delete($f);
             }
         }
     }
     //die();
     return parent::beforeDelete();
     // TODO: Change the autogenerated stub
 }