Esempio n. 1
1
 /**
  * Function that gets called on a job
  * Push::queue('smsSender', $emergency);
  *
  * @param $job
  * @param Emergency $emergency
  */
 public function fire($job, $image)
 {
     $s3 = AWS::get('s3');
     $image = Image::find($image['id']);
     if (!$image) {
         return $job->delete();
     }
     try {
         $imageUtil = new ImageUtil($image->origin);
         $galleryImageUtil = new ImageUtil($image->origin);
     } catch (Exception $e) {
         return $job->delete();
     }
     $image->thumbnail = $this->uploadImage($s3, $imageUtil->resize2('thumbnail')->getImage());
     Log::debug("From queue: Thumbnail: width - {$imageUtil->getWidth()}, height - {$imageUtil->getHeight()}");
     Log::debug("Thumbnail URL: {$image->thumbnail}");
     $this->preventMemoryLeak();
     $image->regular = $this->uploadImage($s3, $galleryImageUtil->resize2('gallery')->getImage());
     Log::debug("From queue: Gallery: width - {$galleryImageUtil->getWidth()}, height - {$galleryImageUtil->getHeight()}");
     Log::debug("Gallery URL: {$image->regular}");
     $this->preventMemoryLeak();
     $image->width = $galleryImageUtil->getWidth();
     $image->height = $galleryImageUtil->getHeight();
     $image->save();
     return $job->delete();
 }
Esempio n. 2
0
function deleteFromS3($key, $key_type = 'folder')
{
    $s3 = AWS::createClient('s3');
    if ($key_type == 'file') {
        $key = str_replace(Config::get('aws.s3_assets_uri') . '/', '', $key);
    }
    $result = $s3->deleteMatchingObjects(Config::get('aws.bucket'), $key);
}
 public function testUploadS3()
 {
     $s3Mock = m::mock();
     $s3Mock->shouldReceive('putObject')->andReturn(true);
     AWS::shouldReceive('get')->once()->with('s3')->andReturn($s3Mock);
     $this->databaseMock->shouldReceive('getFileExtension')->once()->andReturn('sql');
     $this->databaseMock->shouldReceive('dump')->once()->andReturn(true);
     $this->tester->execute(array('--upload-s3' => 'bucket-title'));
     // $this->assertRegExp("/^(\\033\[[0-9;]*m)*(\\n)*Database backup was successful. [A-Za-z0-9_]{10,}.sql was saved in the dumps folder.(\\n)*(\\033\[0m)*(\\033\[[0-9;]*m)*(\\n)*Upload complete.(\\n)*(\\033\[0m)*$/", $this->tester->getDisplay());
 }
Esempio n. 4
0
 public function testKeepOnlyS3()
 {
     $s3Mock = m::mock();
     $s3Mock->shouldReceive('putObject')->andReturn(true);
     AWS::shouldReceive('get')->once()->with('s3')->andReturn($s3Mock);
     File::shouldReceive('delete')->once()->andReturn(true);
     $this->databaseMock->shouldReceive('getFileExtension')->once()->andReturn('sql');
     $this->databaseMock->shouldReceive('dump')->once()->andReturn(true);
     $this->tester->execute(array('--upload-s3' => 'bucket-title', '--keep-only-s3' => true));
 }
Esempio n. 5
0
 /**
  * Create instance of an AWS resource
  */
 public static function instance($type = null)
 {
     if (empty($type)) {
         $class = get_called_class();
         $type = $class::$_resource;
     }
     if (empty(self::$_instances[$type])) {
         self::$_instances[$type] = AWS::factory()->get($type);
     }
     return self::$_instances[$type];
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $s3 = AWS::get('s3');
     $s3Bucket = 'buildbrighton-bbms';
     if (Request::hasFile('image')) {
         $file = Request::file('image');
         $event = Request::get('textevent');
         $time = Request::get('time');
         $fileData = Image::make($file)->encode('jpg', 80);
         $date = Carbon::createFromFormat('YmdHis', $event);
         $folderName = $date->hour . ':' . $date->minute . ':' . $date->second;
         try {
             $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '/' . $time . '.jpg';
             $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $fileData, 'ACL' => 'public-read', 'ContentType' => 'image/jpg', 'ServerSideEncryption' => 'AES256'));
         } catch (\Exception $e) {
             \Log::exception($e);
         }
         //Log::debug('Image saved :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename);
     }
     if (Request::get('eventend') == 'true') {
         $event = Request::get('textevent');
         $date = Carbon::createFromFormat('YmdHis', $event);
         $folderName = $date->hour . ':' . $date->minute . ':' . $date->second;
         $iterator = $s3->getIterator('ListObjects', array('Bucket' => $s3Bucket, 'Prefix' => \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName));
         $images = [];
         $imageDurations = [];
         foreach ($iterator as $object) {
             $images[] = 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $object['Key'];
             $imageDurations[] = 35;
         }
         if (count($images) <= 2) {
             //only two images, probably two bad frames
             //delete them
             foreach ($iterator as $object) {
                 Log::debug("Deleting small event image " . $object['Key']);
                 $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]);
             }
             return;
         }
         $gc = new GifCreator();
         $gc->create($images, $imageDurations, 0);
         $gifBinary = $gc->getGif();
         //Delete the individual frames now we have the gif
         foreach ($iterator as $object) {
             //Log::debug("Processed gif, deleting frame, ".$object['Key']);
             $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]);
         }
         //Save the gif
         $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '.gif';
         $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $gifBinary, 'ACL' => 'public-read', 'ContentType' => 'image/gif', 'ServerSideEncryption' => 'AES256'));
         //Log::debug('Event Gif generated :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename);
         \Slack::to("#cctv")->attach(['image_url' => 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $newFilename, 'color' => 'warning'])->send('Movement detected');
     }
 }
Esempio n. 7
0
 public function setColors()
 {
     AWS::createClient('s3')->getObject(array('Bucket' => Credential::AWSS3BucketLargeThumbs, 'Key' => $this->bannerImage->filename, 'SaveAs' => public_path() . '/media/temp/' . $this->bannerImage->filename));
     // Fetch an RGB array of the dominant color
     $rgb = ColorThief::getColor(public_path() . '/media/temp/' . $this->bannerImage->filename);
     // Unlink the file, it is no longer needed.
     unlink(public_path() . '/media/temp/' . $this->bannerImage->filename);
     // Convert RGB array to hex
     $hex = '#' . dechex($rgb[0]) . dechex($rgb[1]) . dechex($rgb[2]);
     // Set properties
     $this->attributes['dark_color'] = $hex;
     $this->attributes['light_color'] = '#' . (new Color($hex))->lighten();
 }
 public function store()
 {
     foreach (Input::file() as $file) {
         $imagename = $file->getClientOriginalName();
         $mime = $file->getMimeType();
         //TODO: resize and format image
         //$uploadFlag = $file->move('public/uploads', $imagename); //local method
         $s3 = AWS::get('s3');
         $uploadFlag = $s3->putObject(array('Bucket' => self::$bucket, 'Key' => 'uploads/' . $imagename, 'SourceFile' => $file->getRealPath(), 'ACL' => 'public-read', 'StorageClass' => 'REDUCED_REDUNDANCY', 'ContentType' => $mime));
         if ($uploadFlag) {
             $uploadedImages[] = $imagename;
             return Response::json(['success' => true, 'message' => 'Images uploaded', 'images' => $uploadedImages]);
         }
     }
 }
Esempio n. 9
0
 public function fire($job, $data)
 {
     $s3 = \AWS::createClient('s3');
     try {
         $response = $s3->getObject(array('Bucket' => $data['bucket'], 'Key' => $data['key']));
     } catch (Exception $e) {
         return;
     }
     $imagine = new Imagine();
     $image = $imagine->load((string) $response->get('Body'));
     $size = new Box(100, 100);
     $thumb = $image->thumbnail($size);
     $s3->putObject(array('Bucket' => 'bellated', 'Key' => $data['hash'] . '_100x100.' . $data['ext'], 'Body' => $thumb->get($data['ext']), 'ContentType' => $data['mimetype']));
     // Probaby save these to a database here
 }
Esempio n. 10
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->deleteFiles(['thumbnail', 'gallery', 'origin', 'avatar_origin', 'avatar_large', 'avatar_middle', 'avatar_small']);
     $s3 = AWS::get('s3');
     $prefix = 'https://yolanothertest.s3-us-west-2.amazonaws.com/';
     $objects = $s3->getIterator('listObjects', ['Bucket' => 'yolanothertest']);
     foreach ($objects as $object) {
         $imageUrl = $prefix . $object['Key'];
         if ($thumbnail = Image::where('thumbnail', $prefix . $object['Key'])->whereNotNull('imageable_id')->first()) {
             if ($thumbnail) {
                 File::append(storage_path('thumbnail.csv'), "{$thumbnail->id}, {$object['Key']}, {$thumbnail->imageable_type}, {$thumbnail->imageable_id}, {$object['Size']}, " . $this->getImageSize($imageUrl) . PHP_EOL);
                 $this->line("{$thumbnail->id} thumbnail {$object['Key']} {$thumbnail->imageable_type} {$thumbnail->imageable_id} {$object['Size']}");
             }
         } elseif ($large = Image::where('regular', $prefix . $object['Key'])->whereNotNull('imageable_id')->first()) {
             if ($large) {
                 File::append(storage_path('gallery.csv'), "{$large->id},  {$object['Key']}, {$large->imageable_type}, {$large->imageable_id}, {$object['Size']}, " . $this->getImageSize($imageUrl) . PHP_EOL);
                 $this->line("{$large->id} gallery {$object['Key']} {$large->imageable_type} {$large->imageable_id} {$object['Size']}");
             }
         } elseif ($origin = Image::where('origin', $prefix . $object['Key'])->whereNotNull('imageable_id')->first()) {
             if ($origin) {
                 File::append(storage_path('origin.csv'), "{$origin->id}, {$object['Key']}, {$origin->imageable_type}, {$origin->imageable_id}, {$object['Size']}, " . $this->getImageSize($imageUrl) . PHP_EOL);
             }
         } elseif ($avatarOrigin = User::where('img_origin', $prefix . $object['Key'])->first()) {
             if ($avatarOrigin) {
                 File::append(storage_path('avatar_origin.csv'), "{$avatarOrigin->id}, {$object['Key']}, {$object['Size']}, " . $this->getImageSize($imageUrl) . PHP_EOL);
             }
         } elseif ($avatarLarge = User::where('img_large', $prefix . $object['Key'])->first()) {
             if ($avatarLarge) {
                 File::append(storage_path('avatar_large.csv'), "{$avatarLarge->id}, {$object['Key']}, {$object['Size']}, " . $this->getImageSize($imageUrl) . PHP_EOL);
             }
         } elseif ($avatarMiddle = User::where('img_middle', $prefix . $object['Key'])->first()) {
             if ($avatarMiddle) {
                 File::append(storage_path('avatar_middle.csv'), "{$avatarMiddle->id}, {$object['Key']}, {$object['Size']}, " . $this->getImageSize($imageUrl) . PHP_EOL);
             }
         } elseif ($avatarSmall = User::where('img_small', $prefix . $object['Key'])->first()) {
             if ($avatarSmall) {
                 File::append(storage_path('avatar_small.csv'), "{$avatarSmall->id}, {$object['Key']}, {$object['Size']}, " . $this->getImageSize($imageUrl) . PHP_EOL);
             }
         }
     }
 }
Esempio n. 11
0
 /**
  *
  */
 public function postUpload()
 {
     $rules = ['file' => 'required|image|max:' . $this->imageSizeLimit];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator->errors())->withInput();
     }
     DB::transaction(function () {
         $userImage = new UserImage();
         $userImage->user_id = Auth::id();
         $userImage->save();
         // resize
         $path = tempnam(storage_path('images'), 'image');
         $image = Image::make(Input::file('file'));
         $image->fit($this->imageWidth, $this->imageHeight);
         $image->save($path);
         /** @var \Aws\S3\S3Client $s3 */
         $s3 = AWS::get('s3');
         $s3->putObject(['Bucket' => $this->imageBucket, 'Key' => '/demo/' . $userImage->id . '.jpg', 'SourceFile' => $path]);
         $image->destroy();
         File::delete($path);
     });
     return Redirect::to('/');
 }
Esempio n. 12
0
 public function setAvatar($img)
 {
     $s3 = AWS::get('s3');
     $thumbnailPlaceholder = S3_PUBLIC . 'placeholder_128.png';
     $profilePlaceholder = S3_PUBLIC . 'placeholder_64.png';
     $imageUtil = new ImageUtil($img);
     $this->img_origin = $this->uploadImage($s3, $imageUtil->getImage());
     $imageUtil->getImage()->destroy();
     $imageUtil = null;
     preventMemoryLeak();
     $imageUtil2 = new ImageUtil($img);
     $this->img_large = $this->uploadImage($s3, $imageUtil2->resize2('avatar.gallery')->getImage());
     $imageUtil2->getImage()->destroy();
     $imageUtil = null;
     preventMemoryLeak();
     $imageUtil3 = new ImageUtil($img);
     $this->img_middle = $this->uploadImage($s3, $imageUtil3->resize2('avatar.profile')->getImage()) ?: $profilePlaceholder;
     $imageUtil3->getImage()->destroy();
     $imageUtil3 = null;
     preventMemoryLeak();
     $imageUtil4 = new ImageUtil($img);
     $this->img_small = $this->uploadImage($s3, $imageUtil4->resize2('avatar.thumbnail')->getImage()) ?: $thumbnailPlaceholder;
     $imageUtil4->getImage()->destroy();
     $imageUtil4 = null;
     preventMemoryLeak();
 }
Esempio n. 13
0
 private function upload($id, $type, $image)
 {
     $s3 = AWS::get('s3');
     try {
         $fileName = $id . '-' . $type;
         $uploadedImage = $s3->putObject(array('ContentType' => 'image/jpg', 'ACL' => 'bucket-owner-read', 'Bucket' => S3_PRIVATE_BUCKET_NAME, 'Key' => $fileName, 'Body' => $image->encode('jpg', IMAGE_COMPRESSING_QUALITY)));
         return $fileName;
     } catch (S3Exception $e) {
         //			dd($e);
         return null;
     }
 }
Esempio n. 14
0
 public function resize($source_path, $desired_x = 300, $desired_y = 150, $mode = 'crop', $upload = true)
 {
     //TODO: resize with GD library.
     list($source_width, $source_height, $source_type) = getimagesize($source_path);
     //create object depending on image type
     switch ($source_type) {
         case IMAGETYPE_GIF:
             $source_gdim = imagecreatefromgif($source_path);
             break;
         case IMAGETYPE_JPEG:
             $source_gdim = imagecreatefromjpeg($source_path);
             break;
         case IMAGETYPE_PNG:
             $source_gdim = imagecreatefrompng($source_path);
             break;
     }
     $source_aspect_ratio = $source_width / $source_height;
     $desired_aspect_ratio = $x / $desired_y;
     if ($source_aspect_ratio > $desired_aspect_ratio) {
         /*
          * Triggered when source image is wider
          */
         $temp_height = $desired_y;
         $temp_width = (int) ($desired_y * $source_aspect_ratio);
     } else {
         /*
          * Triggered otherwise (i.e. source image is similar or taller)
          */
         $temp_width = $desired_x;
         $temp_height = (int) ($desired_x / $source_aspect_ratio);
     }
     //Resize the image into a temporary GD image
     $temp_gdim = imagecreatetruecolor($temp_width, $temp_height);
     imagecopyresampled($temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height);
     //Copy cropped region from temporary image into the desired GD image
     $x0 = ($temp_width - $desired_x) / $desired_y;
     $y0 = ($temp_height - $desired_y) / 2;
     $desired_gdim = imagecreatetruecolor($desired_x, $desired_y);
     imagecopy($desired_gdim, $temp_gdim, 0, 0, $x0, $y0, $desired_x, $desired_y);
     $application = Application::getApplication();
     if ($upload) {
         //we gotta push this file locally first regardless of if we need it or not
         //since there's no method to get the image data out directly without
         //outputting to browser..
         try {
             $destinationPath = storage_path() . "/uploads/";
             $sourcePathInfo = pathinfo(Img::get($source_path, $desired_x, $desired_y, $mode));
             $newBaseName = $sourcePathInfo['basename'];
             switch ($source_type) {
                 case IMAGETYPE_GIF:
                     $loc = imagegif($source_path, $destinationPath . '/' . $newBaseName);
                     break;
                 case IMAGETYPE_JPEG:
                     $loc = imagejpeg($source_path, $destinationPath . '/' . $newBaseName);
                     break;
                 case IMAGETYPE_PNG:
                     $loc = imagepng($source_path, $destinationPath . '/' . $newBaseName);
                     break;
             }
             $finalUrl = "//" . $_SERVER['SERVER_NAME'] . "/uploads/{$newBaseName}";
         } catch (Exception $e) {
             dd($e->getMessage());
             //TODO: proper error handling should really take place here..
             //in the mean time we'll make do with a dd.
         }
         //at this point we should have created the smaller image, and moved it
         //into the storage folder. The local uri should be set correctly into
         //$loc, and the finalUrl should also be correct.
         if (@$application->getSetting('Enable s3')) {
             //we need to upload this into the s3
             //$uploadFolder
             //file and folder need to be concated and checked.
             if (@$application->getSetting('s3 Folder')) {
                 $pth = trim(@$application->getSetting('s3 Folder'), '/\\ ') . '/' . $fileName;
             } else {
                 $pth = $fileName;
             }
             switch ($source_type) {
                 case IMAGETYPE_GIF:
                     $source_gdim = imagecreatefromgif($source_path);
                     break;
                 case IMAGETYPE_JPEG:
                     $source_gdim = imagecreatefromjpeg($source_path);
                     break;
                 case IMAGETYPE_PNG:
                     $source_gdim = imagecreatefrompng($source_path);
                     break;
             }
             $s3 = AWS::get('s3');
             $s3->putObject(array('Bucket' => @$application->getSetting('s3 Bucket'), 'Key' => $pth, 'SourceFile' => $loc, 'ACL' => 'public-read'));
             if (@$application->getSetting('s3 Cloudfront Url')) {
                 $cloudUrl = trim($application->getSetting('s3 Cloudfront Url'), " /");
                 $finalUrl = "//{$cloudUrl}/{$pth}";
             } else {
                 $finalUrl = "//" . @$application->getSetting('s3 Bucket') . "/{$pth}";
             }
         }
     }
 }
Esempio n. 15
0
 /**
  * Generate AWS S3 URL for downloading MP3 file.
  * 
  * @param Product $product - An instance of product.
  * @param string $link_expiry - Duration of link validity; defaults to NULL (no expiry - AWS *PUBLIC* link).
  * @return string Default file name
  */
 public static function generateAwsS3Url(Product $product, $link_expiry = NULL)
 {
     Log::debug("generateAwsS3Url() - product attribute: " . print_r($product, TRUE));
     Log::debug("Attributes of 'product': " . $product->workshop_year . '_' . $product->speaker_first_name . '_' . $product->speaker_last_name . '_' . $product->session_title);
     $url = array();
     $dl_filename = Utility::generateDownloadFilename($product);
     $s3Buckets = \Config::get('workshop.s3_bucket_list');
     $bucket = $s3Buckets[$product->workshop_year];
     $s3FileNameFormat = \Config::get('workshop.s3_file_name_format');
     $fileNameFormat = $s3FileNameFormat[$product->workshop_year];
     if (!$link_expiry) {
         $link_expiry = '+10 min';
     }
     if ($product->mp3_free_ind) {
         //$bucket = $s3Buckets['free'];
     }
     $prod_code = $product->prod_code;
     // Create link for each MP3 file that belongs to product.
     for ($i = 1; $i <= $product->unit_count; $i++) {
         if ($product->unit_count > 1) {
             $suffixList = array(1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D');
             $prod_code = substr($product->prod_code, 0, 4) . $suffixList[$i] . substr($product->prod_code, 4);
             $dl_filename = str_replace('.mp3', '_' . $suffixList[$i] . '.mp3', $dl_filename);
         }
         $s3FileName = $fileNameFormat['heading'] . $prod_code . $fileNameFormat['ext'];
         // Use *signed* link URL for all downloads, even for free downloads.
         $s3 = AWS::get('s3');
         $url[$i] = $s3->getObjectUrl($bucket, $s3FileName, $link_expiry, array('ResponseContentDisposition' => 'attachment; filename="' . $dl_filename . '"', 'ResponseContentType' => 'audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3', 'ResponseCacheControl' => 'no-cache'));
         Log::debug("URL for product #" . $product->id . ": " . print_r($url[$i], TRUE));
     }
     return $url;
 }
 private function upload_s3($image, $fileName, $mime, $folder)
 {
     $s3 = AWS::get('s3');
     $s3->putObject(array('Bucket' => 'images.jacksonlive.es', 'Key' => "test/{$folder}/{$fileName}", 'Body' => "{$image}", 'ACL' => 'public-read', 'ContentType' => $mime));
 }
 /**
  * Prepare to handle FileManager API requests
  *
  * Construct an AmazonS3 Service instance then configure configure paths, etc.
  *
  * @param type  $config plugin specific configuration
  *
  * @todo  throw error if keys are not set
  */
 public function __construct($config = [])
 {
     parent::__construct($config);
     $this->bucket = \Config::get('filemanager.bucket');
     $this->s3 = \AWS::get('s3');
     $this->domain = str_replace('https://', '', $this->s3->getBaseUrl());
     //		// Configure instance
     //		$this->configure($this->config);
 }
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function () {
    return View::make('hello');
});
Route::get('/complete', function () {
    return View::make('complete');
});
// Upload an image to S3 and
// create a job to process it
Route::post('/', function () {
    $validator = Validator::make(Input::all(), array('title' => 'required', 'file' => 'required|mimes:jpeg,jpg,png'));
    if ($validator->fails()) {
        return Redirect::to('/');
    }
    // Upload File
    $file = Input::file('file');
    $now = new DateTime();
    $hash = md5($file->getClientOriginalName() . $now->format('Y-m-d H:i:s'));
    $key = $hash . '.' . $file->getClientOriginalExtension();
    $s3 = AWS::get('s3');
    $s3->putObject(array('Bucket' => 'testprocqueue', 'Key' => $key, 'SourceFile' => $file->getRealPath(), 'ContentType' => $file->getClientMimeType()));
    // Create job
    Queue::push('\\Proc\\Worker\\ImageProcessor', array('bucket' => 'testprocqueue', 'hash' => $hash, 'key' => $key, 'ext' => $file->getClientOriginalExtension(), 'mimetype' => $file->getClientMimeType()));
    return Redirect::to('/complete');
});
Esempio n. 19
0
 function __construct(CollectionTransformer $collectionTransformer)
 {
     $this->collectionTransformer = $collectionTransformer;
     $this->s3 = AWS::get('s3');
     //		ini_set('memory_limit', '256M');
 }
Esempio n. 20
0
|
*/
Route::get('/', function () {
    return View::make('hello');
});
Route::get('/complete', function () {
    return View::make('complete');
});
Route::get('lord', function () {
    $user = getenv('DB_USERNAME');
    dd($user);
});
// Upload an image to S3 and
// create a job to process it
Route::post('/', function () {
    $validator = Validator::make(Input::all(), array('title' => 'required', 'file' => 'required|mimes:jpeg,jpg,png'));
    if ($validator->fails()) {
        return Redirect::to('/');
    }
    // Upload File
    $file = Input::file('file');
    $now = new DateTime();
    $hash = md5($file->getClientOriginalName() . $now->format('Y-m-d H:i:s'));
    $key = $hash . '.' . $file->getClientOriginalExtension();
    $s3 = AWS::createClient('s3');
    $s3->putObject(array('Bucket' => 'bellated', 'Key' => $key, 'SourceFile' => $file->getRealPath(), 'ContentType' => $file->getClientMimeType()));
    // Create job
    Queue::push('\\Proc\\Worker\\ImageProcessor', array('bucket' => 'bellated', 'hash' => $hash, 'key' => $key, 'ext' => $file->getClientOriginalExtension(), 'mimetype' => $file->getClientMimeType()));
    Log::info('queue processed');
    return Redirect::to('/complete');
});
Esempio n. 21
0
 /**
  * Create a new command instance.
  */
 public function __construct()
 {
     parent::__construct();
     $this->s3 = AWS::get('s3');
 }
 public function deleteimage()
 {
     /* S3 delete */
     // this function deletes preview file on s3.
     $removed_image = Input::get('removed_image');
     //former name
     $destinationPath = 'public/pb-uploads/pet_images/';
     // upload path
     $thumbnail_path = 'public/pb-uploads/pet_images_thumbnail/';
     $saved_temp_id = Session::get('saved_temp_id');
     $saved_img = Petimage::where('original_name', '=', $removed_image)->first();
     $image_name = $saved_img->image_name;
     //File::delete($destinationPath.$image_name);
     //File::delete($thumbnail_path.$image_name);
     // $saved_img->delete();
     // $s3_url_domain = 'https://s3.amazonaws.com/';
     //$s3_bucket = 'popibay-bucket-s3/';
     $s3_destination_path = 'popibay/pb-uploads/pet_images/' . $image_name;
     $s3_thumbnail_path = 'popibay/pb-uploads/pet_images_thumbnail/' . $image_name;
     //$destination_path_to_s3 = 'pb-uploads/pet_images/';
     //$thumbnail_path_to_s3 = 'pb-uploads/pet_images_thumbnail/';
     //$s3_destination_path_db = $s3_bucket.'popibay/pb-uploads/pet_images/';
     //$s3_thumbnail_path_db = $s3_bucket.'popibay/pb-uploads/pet_images_thumbnail/';
     $s3 = AWS::get('s3');
     $s3->deleteObject(array('Bucket' => 'popibay-bucket-s3', 'Key' => $s3_destination_path));
     $s3 = AWS::get('s3');
     $s3->deleteObject(array('Bucket' => 'popibay-bucket-s3', 'Key' => $s3_thumbnail_path));
     $saved_img->delete();
 }