public function handleS3(StoreS3Request $request) { $credentials = filesystem()->store('s3', $request->all()); if ($this->storageRepository->testAndStoreCredentials(Auth::id(), $credentials)) { flash()->success('Storage successfully added'); } else { flash()->error('There was a problem verifying the connection credentials'); } return redirect()->route('storage_path'); }
public function testAndStoreCredentials($userId, $credentials) { $testing = filesystem()->init($credentials); try { $testing->listContents(); // If that didn't break anything continue... $this->saveCredentials($userId, $credentials); return true; } catch (\Exception $e) { return false; } }
private function testAndStoreCredentials($credentials) { $testing = filesystem()->init($credentials); try { $testing->listContents(); // If that didn't break anything continue... $this->storageRepository->saveCredentials(Auth::id(), $credentials); flash()->success('Storage successfully added'); } catch (\Exception $e) { $this->testError = $e->getMessage(); flash()->error('There was a problem verifying the connection credentials'); } return redirect()->route('storage_path'); }
public function download($crypt) { $details = json_decode(Crypt::decrypt($crypt)); $file = $this->fileRepository->getForDownload($details->file_id, $details->droplet_id); $filesystem = filesystem()->init($file->filesystem()); if ($filesystem->has($file->droplet->present()->directory . '/' . $file->file_name)) { header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); header("Content-type: {$file->type}"); header("Content-Disposition: attachment; filename={$file->file_name}"); header("Expires: 0"); header("Pragma: public"); echo $filesystem->read($file->droplet->present()->directory . '/' . $file->file_name); } }
/** * @param $value */ protected function uploadImage($value) { if (isset($this->attributes[$value]) && $this->attributes[$value] != '') { $filename = public_path() . '/uploads/' . $this->attributes[$value]; if (filesystem()->exists($filename)) { filesystem()->delete($filename); } } if ($value == '') { $this->attributes[$value] = ''; } else { $filename = time() . str_random(10); $value->move(public_path() . '/uploads/', $filename); $this->attributes[$value] = $filename; } }
/** * Register any application services. * * This service provider is a great spot to register your various container * bindings with the application. As you can see, we are registering our * "Registrar" implementation here. You can add your own bindings too! * * @return void */ public function register() { $this->app->bind('Illuminate\\Contracts\\Auth\\Registrar', 'Nimbus\\Services\\Registrar'); $this->app->singleton('Nimbus\\Glide\\Server', function ($app) { // Set image source $source = filesystem()->init(env('DEFAULT_FILESYSTEM')); // Set image cache $cache = filesystem()->init(env('GLIDE_CACHE')); // Set image manager $imageManager = new \Intervention\Image\ImageManager(['driver' => env('INTERVENTION_DRIVER', 'gd')]); // Set manipulators $manipulators = [new \League\Glide\Api\Manipulator\Orientation(), new \League\Glide\Api\Manipulator\Rectangle(), new \League\Glide\Api\Manipulator\Size(2000 * 2000), new \League\Glide\Api\Manipulator\Brightness(), new \League\Glide\Api\Manipulator\Contrast(), new \League\Glide\Api\Manipulator\Gamma(), new \League\Glide\Api\Manipulator\Sharpen(), new \League\Glide\Api\Manipulator\Filter(), new \League\Glide\Api\Manipulator\Blur(), new \League\Glide\Api\Manipulator\Pixelate(), new \Nimbus\Glide\Manipulator\Watermark($source), new \League\Glide\Api\Manipulator\Output()]; // Set API $api = new \League\Glide\Api\Api($imageManager, $manipulators); // Setup Glide server $server = new \Nimbus\Glide\Server($source, $cache, $api); $server->setBaseUrl('/img/'); $server->setCachePathPrefix('.cache'); return $server; }); }
public function makeImage() { $request = $this->resolveRequestObject(func_get_args()); if ($this->cacheFileExists($request) === true) { return $request; } // Set the source here... $parts = explode('/', $request->path); if (count($parts) > 2) { array_shift($parts); } $storage = DB::table('storages')->join('files', 'storages.id', '=', 'files.storage_id')->join('droplets', 'files.droplet_id', '=', 'droplets.id')->where('files.file_name', '=', $parts[1])->where('droplets.slug', '=', $parts[0])->select('storages.credentials')->first(); if (!empty($storage)) { $this->setSource(filesystem()->init($storage->credentials)); } // if ($this->sourceFileExists($request) === false) { throw new NotFoundException('Could not find the image `' . $this->getSourcePath($request) . '`.'); } $source = $this->source->read($this->getSourcePath($request)); if ($source === false) { throw new FilesystemException('Could not read the image `' . $this->getSourcePath($request) . '`.'); } $tmp = tempnam(sys_get_temp_dir(), ''); $handle = fopen($tmp, "w"); fwrite($handle, $source); try { $write = $this->cache->write($this->getCachePath($request), $this->api->run($request, $tmp)); } catch (FileExistsException $exception) { // Cache file failed to write. Fail silently. unlink($tmp); return $request; } unlink($tmp); if ($write === false) { throw new FilesystemException('Could not write the image `' . $this->getCachePath($request) . '`.'); } return $request; }
/** * Write the contents string to the specified path. * * @param string $path The file path to which to $contents should be written * @param string $contents The data to write to the specified $path * @return \Amp\Promise A promise resolving to the integer length written upon success */ function put($path, $contents) { return filesystem()->put($path, $contents); }