/** *@depends testCreateBucket */ public function testPutFile($s3_client) { //start create laravel filesystem adapter $cloud_adapter = new AwsS3Adapter($s3_client, $this->bucket_name, $this->root_folder_in_bucket); $filesystem = new Filesystem($cloud_adapter); $laravel_filesystem_adapter = new FilesystemAdapter($filesystem); //end create laravel filesystem adapter //start pul file $laravel_filesystem_adapter->put($this->bucket_file_path, $this->bucket_file_content, FilesystemContract::VISIBILITY_PUBLIC); //end put file //start check file exists $this->assertTrue($laravel_filesystem_adapter->exists($this->bucket_file_path)); //end check file exists //start check contect of file $this->assertEquals($this->bucket_file_content, $laravel_filesystem_adapter->get($this->bucket_file_path)); //end check contect of file return $laravel_filesystem_adapter; }
public function makeUploadedImageThumbnail(Image $image) { // Download the previously saved image and make a thumbnail of it $contents = $this->storage->get($image->directory . '/' . $image->filename); if (!$contents) { return false; } // Temp file to store the downloaded image $tmpFile = $this->makeTmpFile(); // Save downloaded image locally file_put_contents($tmpFile->getPathname(), $contents); // and set it as the working image $this->file = $tmpFile; // Make a smaller version for showing on site $thumbFile = $this->makeThumbnailImage(100, 100); // Copy to S3 $this->storage->getDriver()->put($image->directory . 'thumbs/' . $image->filename, file_get_contents($thumbFile->getPathname()), ['StorageClass' => 'REDUCED_REDUNDANCY']); // Delete the local temp thumb unlink($thumbFile->getPathname()); // Update the image so it has a thumb $image->thumb = true; $image->save(); return true; }
/** * Get the contents of a file. * * @param string $path * @return string * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException * @static */ public static function get($path) { return \Illuminate\Filesystem\FilesystemAdapter::get($path); }
/** * Renames existing file * * @param string $oldFileName * @param string $newFileName * @param string $context * @param FilesystemAdapter $filesystemAdapter * * @return boolean */ public function rename($oldFileName, $newFileName, $context, FilesystemAdapter $filesystemAdapter) { if ($filesystemAdapter->exists($context . '/' . $newFileName)) { throw new IcrRuntimeException("File with name {$newFileName} already exists!"); } $image = $filesystemAdapter->get($context . '/' . $oldFileName); $filesystemAdapter->move($context . '/' . $oldFileName, $context . '/' . $newFileName); foreach ($this->config[$context] as $sizeName => $value) { $oldPath = $context . '/' . $sizeName . '/' . $oldFileName; $newPath = $context . '/' . $sizeName . '/' . $newFileName; $filesystemAdapter->move($oldPath, $newPath); } return true; }