Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function delete($path)
 {
     try {
         $this->s3->deleteObject(['Bucket' => $this->bucket, 'Key' => $path]);
     } catch (AwsExceptionInterface $e) {
         throw Exception\StorageException::deleteError($path, $e);
     }
 }
Exemple #2
0
 /**
  * @param $filename
  * @return \Aws\Result|null
  */
 public function remove($filename)
 {
     $result = null;
     try {
         $result = $this->s3->deleteObject(['Bucket' => $this->bucket, 'Key' => $filename]);
     } catch (\Exception $e) {
     }
     return $result;
 }
 /**
  * @param $path
  *
  * @return bool
  * @throws FileException
  */
 public function delete($path)
 {
     try {
         $this->s3->deleteObject(['Bucket' => $this->bucket, 'Key' => $path]);
     } catch (\Exception $e) {
         throw new FileException('File was not removed from filesystem', $e->getCode(), $e);
     }
     return true;
 }
Exemple #4
0
 /**
  * Delete remote file
  *
  * @param string $path Remote Path
  *
  * @return bool
  * @throws
  */
 public function delete($path)
 {
     $path = trim($path, '/');
     if (!$this->isFile($path)) {
         $path = $this->bucket . "/" . $path;
         throw new ExceptionStorage("File {$path} Not found or Not Is File", static::E_NOT_IS_FILE);
     }
     $response = $this->clientS3->deleteObject(array('Bucket' => $this->bucket, 'Key' => $path));
     return (bool) $response;
 }
 /**
  * {@inheritDoc}
  */
 public function remove(array $paths, array $filters)
 {
     if (empty($paths) && empty($filters)) {
         return;
     }
     if (empty($paths)) {
         try {
             $this->storage->deleteMatchingObjects($this->bucket, null, sprintf('/%s/i', implode('|', $filters)));
         } catch (\Exception $e) {
             $this->logError('The objects could not be deleted from Amazon S3.', array('filter' => implode(', ', $filters), 'bucket' => $this->bucket, 'exception' => $e));
         }
         return;
     }
     foreach ($filters as $filter) {
         foreach ($paths as $path) {
             $objectPath = $this->getObjectPath($path, $filter);
             if (!$this->objectExists($objectPath)) {
                 continue;
             }
             try {
                 $this->storage->deleteObject(array('Bucket' => $this->bucket, 'Key' => $objectPath));
             } catch (\Exception $e) {
                 $this->logError('The object could not be deleted from Amazon S3.', array('objectPath' => $objectPath, 'filter' => $filter, 'bucket' => $this->bucket, 'exception' => $e));
             }
         }
     }
 }
 /**
  * rename file/directory
  *
  * @return string
  */
 public function rename()
 {
     $oldPath = $this->sanitizePath($this->get['old']);
     $isDir = $this->isDir($this->metadata("{$oldPath}"));
     $oldPath .= $isDir ? '/' : '';
     $contents = $isDir ? $this->s3->listObjects(['Bucket' => $this->bucket, 'Prefix' => $oldPath])['Contents'] : array();
     // NOTE: we do this instead of isDir as we only care if there are files under this prefix
     if (count($contents) > 1) {
         $this->error('Unfortunately, we are currently unable to rename a non-empty directory.', false);
     }
     $pathInfo = pathinfo($oldPath);
     $dirName = $pathInfo['dirname'];
     $baseName = $pathInfo['basename'];
     $newFile = $this->get['new'];
     $newPath = join('/', array($dirName, $newFile));
     if ($isDir) {
         $response = $this->createDirectory($newPath);
     } else {
         $response = $this->s3->copyObject(['Bucket' => $this->bucket, 'CopySource' => urlencode($this->bucket . '/' . $oldPath), 'Key' => $newPath]);
         //				array('bucket' => $this->bucket, 'filename' => $oldPath),
         //				array('bucket' => $this->bucket, 'filename' => $newPath),
         //				array('acl' => CannedAcl::PUBLIC_READ)
         //			);
     }
     if (!empty($response)) {
         $this->s3->deleteObject(['Bucket' => $this->bucket, 'Key' => $oldPath]);
         //$this->bucket, $oldPath);
     }
     return array('Error' => '', 'Code' => 0, 'Old Path' => $oldPath, 'Old Name' => $baseName, 'New Path' => $newPath, 'New Name' => $newFile);
 }
 /**
  * Remove file
  *
  * @param  string  $path  file path
  * @return Guzzle\Service\Resource\Model
  **/
 protected function _unlink($path)
 {
     $clear = new \Aws\S3\Model\ClearBucket($this->s3, $this->bucket);
     $iterator = $this->s3->getIterator('ListObjects', array('Bucket' => $this->bucket, 'Prefix' => $this->pathToKey($path)));
     $clear->setIterator($iterator);
     $clear->clear();
     return $this->s3->deleteObject(array("Bucket" => $this->bucket, "Key" => $this->pathToKey($path)));
 }
Exemple #8
0
 /**
  * Deletes an object given its key
  * @param $key Key name on S3 bucket
  * @return bool
  */
 public function deleteFile($key)
 {
     $res = $this->s3Client->deleteObject(array('Bucket' => $this->bucketName, 'Key' => $key));
     if ($res) {
         return true;
     } else {
         return false;
     }
 }
Exemple #9
0
 /**
  * Unpublishes the given persistent resource
  *
  * @param \TYPO3\Flow\Resource\Resource $resource The resource to unpublish
  * @return void
  */
 public function unpublishResource(Resource $resource)
 {
     try {
         $objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($resource);
         $this->s3Client->deleteObject(array('Bucket' => $this->bucketName, 'Key' => $objectName));
         $this->systemLogger->log(sprintf('Successfully unpublished resource as object "%s" (MD5: %s) from bucket "%s"', $objectName, $resource->getMd5() ?: 'unknown', $this->bucketName), LOG_DEBUG);
     } catch (\Exception $e) {
     }
 }
Exemple #10
0
 /**
  * @param string $container
  * @param string $name
  *
  * @throws DfException
  */
 public function deleteBlob($container = '', $name = '')
 {
     try {
         $this->checkConnection();
         $this->blobConn->deleteObject(['Bucket' => $container, 'Key' => $name]);
     } catch (\Exception $ex) {
         throw new DfException('Failed to delete blob "' . $name . '": ' . $ex->getMessage());
     }
 }
 /**
  * Remove dir
  *
  * @param  string  $path  dir path
  * @return bool
  * @author Dmitry (dio) Levashov
  **/
 protected function _rmdir($path)
 {
     $newkey = $this->_normpath($path) . '/';
     try {
         $obj = $this->s3->deleteObject(array('Bucket' => $this->options['bucket'], 'Key' => $newkey));
         return true;
     } catch (Exception $e) {
     }
     return false;
 }
 /**
  * Deletes one or more files from DFS
  *
  * @param string|array $filePath
  *        Single local filename, or array of local filenames
  *
  * @return bool true if deletion was successful, false otherwise
  */
 public function delete($filePath)
 {
     try {
         $this->s3client->deleteObject(array('Bucket' => $this->bucket, 'Key' => $filePath));
         return true;
     } catch (S3Exception $e) {
         eZDebug::writeError($e->getMessage(), __METHOD__);
         return false;
     }
 }
 /**
  * Remove file
  *
  * @param  string  $path  file path
  * @return bool
  * @author Dmitry (dio) Levashov
  **/
 protected function _unlink($path)
 {
     $newkey = $this->_normpath($path);
     $newkey = preg_replace("/\\/\$/", "", $newkey);
     try {
         $obj = $this->s3->deleteObject(array('Bucket' => $this->options['bucket'], 'Key' => $newkey));
         return true;
     } catch (Exception $e) {
     }
     return false;
 }
 /**
  * @param $awsPath aws file  to delete
  * @return mixed|null
  * @throws Exception
  */
 private function deleteObject($bucket, $awsPath)
 {
     $this->logger->debug('delete ' . $awsPath . ' from ' . $bucket . ' bucket ...');
     $result = $this->s3->deleteObject(array('Bucket' => $bucket, 'Key' => $awsPath));
     try {
         return $result;
         $this->logger->debug('delete ' . $awsPath . ' from ' . $bucket . ' bucket ! done');
     } catch (AwsException $e) {
         throw $e;
     }
 }
 public function unlink($path)
 {
     $path = $this->normalizePath($path);
     try {
         $result = $this->connection->deleteObject(array('Bucket' => $this->bucket, 'Key' => $path));
         $this->testTimeout();
     } catch (S3Exception $e) {
         \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function remove($targetPath, $filter)
 {
     if (!$this->objectExists($targetPath)) {
         // A non-existing object to delete: done!
         return true;
     }
     try {
         $response = $this->storage->deleteObject(array('Bucket' => $this->bucket, 'Key' => $targetPath));
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
 /**
  * Delete a file.
  *
  * @param  string            $file
  * @return boolean           Whether the file was deleted
  * @throws \RuntimeException
  */
 public function unlink($file)
 {
     if (null !== $this->filenameFilter) {
         $file = $this->filenameFilter->filter($file);
     }
     $params = array('Bucket' => $this->getBucket(), 'Key' => $file);
     try {
         $this->s3Client->deleteObject($params);
     } catch (S3Exception $e) {
         if (!$this->getThrowExceptions()) {
             return false;
         }
         throw new \RuntimeException('Exception thrown by Aws\\S3\\S3Client: ' . $e->getMessage(), null, $e);
     }
     return true;
 }
 public function testPostObjectProducesCorrectParametersForPost()
 {
     $key = 'dummy.txt';
     // Create the PostObject and fetch the data
     $post = new PostObject($this->client, $this->bucket);
     $post->prepareData();
     $form = $post->getFormAttributes();
     $data = $post->getFormInputs();
     // Use Guzzle to simulate a browser POST upload to S3
     $http = new Client(array('ssl.certificate_authority' => false));
     /** @var $response \Guzzle\Http\Message\Response */
     $response = $http->post($form['action'], null, $data)->addPostFiles(array('file' => __DIR__ . DIRECTORY_SEPARATOR . $key))->send();
     // Verify that the response is as expected
     $this->assertEquals(204, $response->getStatusCode());
     $this->assertEquals("https://{$this->bucket}.s3.amazonaws.com/{$key}", $response->getLocation());
     // Delete the object
     $this->client->deleteObject(array('Bucket' => $this->bucket, 'Key' => $key));
 }
Exemple #19
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
 }
Exemple #20
0
 /**
  * @param string $name
  * @return \Aws\Result
  */
 public function deleteFile($name)
 {
     return $this->client->deleteObject(['Bucket' => $this->getBucket(), 'Key' => $name]);
 }
Exemple #21
0
 /**
  * @param string $localFile
  * @param string $remoteFile
  */
 public function deleteFile($localFile, $remoteFile)
 {
     @unlink($localFile);
     $this->s3Client->deleteObject(array('Bucket' => $this->bucket, 'Key' => $remoteFile));
 }
Exemple #22
0
 /**
  * Delete a file
  *
  * @param   string   $path
  * @return  boolean  delete result
  */
 public function delete($path)
 {
     $options = $this->getOptions($path);
     return $this->client->deleteObject($options);
 }
Exemple #23
0
 /**
  * @param Asset $asset
  */
 public function removeAsset(Asset $asset)
 {
     if (strlen($asset->getRelativeUrl()) > 20) {
         $this->s3Client->deleteObject(['Key' => $asset->getRelativeUrl(), 'Bucket' => $this->bucket]);
     }
 }
Exemple #24
0
 public function testSignsPayload()
 {
     $this->client->putObject(array('Bucket' => $this->bucket, 'Key' => 'test2', 'Body' => 'testing...1234'));
     $this->client->deleteObject(array('Bucket' => $this->bucket, 'Key' => 'test2'));
 }
Exemple #25
0
 /**
  * deleteObject
  *
  * @param string $key
  * @param array  $params
  *
  * @return \Guzzle\Service\Resource\Model
  */
 public function deleteObject($key, array $params = array())
 {
     $params['Key'] = $key;
     $params['Bucket'] = $this->name;
     return $this->client->deleteObject($params);
 }
Exemple #26
0
 public function delete($key)
 {
     $this->load();
     $this->s3Client->deleteObject(["Bucket" => S3Cache::BUCKET, "Key" => $key]);
 }
 public function remove($path)
 {
     return $this->s3->deleteObject(array('Bucket' => $this->getConfigRelativeKey('s3Bucket'), 'Key' => $path));
 }
 $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";
     }
 }
 // upload file to selected bucket
 try {
     $s3->putObject(['Bucket' => $bucket, 'Key' => $filename, 'Body' => $filedata, 'ACL' => 'public-read']);
Exemple #29
0
 /**
  * Removes the null version (if there is one) of an object and inserts a delete marker, which becomes the latest version of the object.
  * If there isn't a null version, Amazon S3 does not remove any objects.
  *
  * @param string $bucket
  * @param string $key
  * @param array  $params
  *
  * @return mixed
  */
 public function deleteObject($bucket, $key, array $params = [])
 {
     $params['Bucket'] = $bucket;
     $params['Key'] = $key;
     return $this->instance->deleteObject($params);
 }
 /**
  * _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;
 }