/** * @param FileWasFailedToUpload $event [description] * @return void */ public function handle(LibraryWasCreated $event) { $library = $event->library; // If the media library was deleted before it moved // Delete this queue if (!$this->libraryRepository->findById($library->id())) { $this->delete(); } $description = $library->description()->value(); $storage = $description['storage']; // We don't need to move if storage is local if ($storage != 'local') { $preferredFilesystem = $this->filesystemFactory->disk($storage); $localFilesystem = $this->filesystemFactory->disk('local'); $destination = $description['path']; $source = $destination; $stream = $localFilesystem->getDriver()->readStream($source); $preferredFilesystem->put($destination, $stream); // Remove local saved file $localFilesystem->delete($source); } // Mark as moved $description['is_moved'] = true; $library->describe(new Description($description)); $this->libraryRepository->save($library); }
/** * Execute the console command. * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ public function handle() { $this->line('Writing sitemap.xml to public disk...'); $siteMap = (string) $this->siteMap; $this->fileSystem->disk('public')->put('sitemap.xml', $siteMap); $this->info(sprintf('Wrote %dkb to sitemap.xml in public disk.', strlen($siteMap) / 1024)); }
/** * Get Home Page Background Image Url * * @return string */ public function getHomePageImageUrl() { $url = url('/images/country.jpg'); if ($this->filesystem->disk('s3')->exists($this->getName())) { $url = $this->filesystem->disk('s3')->getDriver()->getAdapter()->getClient()->getObjectUrl(env('AWS_BUCKET'), $this->getName()); } return $url; }
/** * @param UploadedFile $file * @return mixed */ public function store(UploadedFile $file) { $savedFile = $this->file->createFromFile($file); $path = $this->getDestinationPath($savedFile->getOriginal('path')); $stream = fopen($file->getRealPath(), 'r+'); $this->filesystem->disk($this->getConfiguredFilesystem())->writeStream($path, $stream, ['visibility' => 'public', 'mimetype' => $savedFile->mimetype]); $this->createThumbnails($savedFile); return $savedFile; }
/** * Get the storage that will be used for storing images. * @return FileSystemInstance */ protected function getStorage() { if ($this->storageInstance !== null) { return $this->storageInstance; } $storageType = config('filesystems.default'); $this->storageInstance = $this->fileSystem->disk($storageType); return $this->storageInstance; }
/** * Handle event * * @param LibraryWasDeleted $event * @return void */ public function handle(LibraryWasDeleted $event) { $library = $event->library; $description = $library->description()->value(); $storage = $description['is_moved'] ? $description['storage'] : 'local'; $filesystem = $this->filesystemFactory->disk($storage); if ($filesystem->exists($description['path'])) { $filesystem->delete($description['path']); } }
/** * Get the readme file contents if one exists * @param Package $package * @return string */ private function getReadmeFileFor(Package $package) { $readmeLocation = 'storage/modules/' . $package->getName(); if ($this->diskFactory->disk('local')->exists($readmeLocation . '/readme.md')) { return $this->diskFactory->disk('local')->get($readmeLocation . '/readme.md'); } if ($this->diskFactory->disk('local')->exists($readmeLocation . '/README.md')) { return $this->diskFactory->disk('local')->get($readmeLocation . '/README.md'); } return ''; }
/** * Apply resize * * @param string $path * @return Psr-7 stream */ public function apply($path) { $library = $this->libraryRepostiory->findByPath($path)->toArray(); $storage = $library['description']['is_moved'] ? $library['description']['storage'] : 'local'; $filesystem = $this->filesystemFactory->disk($storage); $stream = $filesystem->getDriver()->readStream($path); $lastModified = $filesystem->lastModified($path); return $this->imageManager->cache(function ($image) use($stream, $lastModified) { $this->process($image->setProperty('lastModified', $lastModified)->make($stream)); }, $this->getLifetime()); }
public function destroyFile($data) { foreach ($data as $files) { $arquivo = $files->name . '.' . $files->extension; if ($this->storage->disk()->exists($arquivo)) { $this->storage->disk()->delete($arquivo); $this->repository->delete($files->id); return ['error' => true, 'message' => 'Arquivo ' . $arquivo . ' do Projeto Excluido']; } } }
/** * Start publishing. * * @param \Illuminate\Config\Repository $config * @param array $options */ public function fire(Command $console, $options) { $this->console = $console; $this->options = (object) $options; $disk = $this->config->get('filesystems.publish_default'); if (!is_null($this->options->to)) { $disk = 'publish_' . $this->options->to; } $this->disk = $this->factory->disk($disk); $this->publish(); }
/** * Perform rule validation * * @param mixed $attribute * @param mixed $value * @param mixed $parameters * @param mixed $validator * * @return bool */ public function validate($attribute, $value, $parameters, $validator) { $path = $value; $mimes = $parameters; $library = $this->libraryRepostory->findByPath($path); if (!$library) { return false; } $library = $library->toArray(); $storage = $library['description']['is_moved'] ? $library['description']['storage'] : 'local'; $mime = $this->filesystemFactory->disk($storage)->mimeType($library['description']['path']); return in_array($mime, $mimes); }
/** * @param FileWasFailedToUpload $event [description] * @return void */ public function handle(FileWasFailedToUpload $event) { $files = $event->uploadedFiles; // When a file is failed to upload // It will remain in local storage $filesystem = $this->filesystemFactory->disk('local'); foreach ($files as $file) { // Ensure file is exist before delete it if ($filesystem->exists($file)) { $filesystem->delete($file); } } }
/** * Return the directory where all files of the given media are stored. * * @param \Spatie\MediaLibrary\Media $media * * @return string */ public function getMediaDirectory(Media $media) { $this->filesystems->disk($media->disk)->put('.gitignore', Gitignore::getContents()); $directory = $media->id; $this->filesystems->disk($media->disk)->makeDirectory($directory); return $directory; }
/** * Return the directory where all files of the given media are stored. * * @param \Spatie\MediaLibrary\Media $media * * @return string */ public function getMediaDirectory(Media $media, $conversion = false) { $pathGenerator = PathGeneratorFactory::create(); $directory = $conversion ? $pathGenerator->getPathForConversions($media) : $pathGenerator->getPath($media); $this->filesystem->disk($media->disk)->makeDirectory($directory); return $directory; }
/** * Upload Pdf to s3 and create contracts * * @param $key */ public function uploadPdfToS3AndCreateContracts($key) { $contracts = $this->getJsonData($key); foreach ($contracts as $contract) { $this->updateContractJsonByID($key, $contract->id, ['create_status' => static::CREATE_PROCESSING], 2); try { $this->storage->disk('s3')->put($contract->file, $this->filesystem->get($this->getFilePath($key, $contract->file))); } catch (Exception $e) { $this->logger->error(sprintf('File could not be uploaded : %s', $e->getMessage())); continue; } $data = ['file' => $contract->file, 'filehash' => $contract->filehash, 'user_id' => $contract->user_id, 'metadata' => $contract->metadata]; try { $con = $this->contract->save($data); $this->logger->activity('contract.log.save', ['contract' => $con->id], $con->id, $con->user_id); $this->updateContractJsonByID($key, $contract->id, ['create_status' => static::CREATE_COMPLETED], 2); if ($con) { $this->queue->push('App\\Nrgi\\Services\\Queue\\ProcessDocumentQueue', ['contract_id' => $con->id]); } $this->logger->info('Contract successfully created.', ['Contract Title' => $con->title]); } catch (Exception $e) { $this->logger->error($e->getMessage()); if ($this->storage->disk('s3')->exists($contract->file)) { $this->storage->disk('s3')->delete($contract->file); } $this->updateContractJsonByID($key, $contract->id, ['create_remarks' => trans('contract.save_fail'), 'create_status' => static::CREATE_FAILED], 2); } $this->deleteFile($key, $contract->file); } }
private function getBaseURL($projetoFile) { switch ($this->storage->getDefaultDriver()) { case 'local': return $this->storage->disk('local')->getAdapter()->getPathPrefix() . '/' . $projetoFile->getFileName(); //return $this->storage->getDrive()->getAdapter()->getPathPrefix() . '/' . $projetoFile->getFileName(); } }
/** * Return the directory where all files of the given media are stored. * * @param \Spatie\MediaLibrary\Media $media * * @return string */ public function getMediaDirectory(Media $media, $conversion = false) { $this->filesystems->disk($media->disk)->put('.gitignore', Gitignore::getContents()); $pathGenerator = PathGeneratorFactory::create(); $directory = $conversion ? $pathGenerator->getPathForConversions($media) : $pathGenerator->getPath($media); $this->filesystems->disk($media->disk)->makeDirectory($directory); return $directory; }
/** * Create new Receiver instance * * @param FilesystemFactory $filesystemFactory * @param Request $request * @param array $config * @return void */ public function __construct(FilesystemFactory $filesystemFactory, Request $request, array $config = []) { // Since the strategy is to save each upload to local storage first, // We need to set the filesystem to local $this->filesystem = $filesystemFactory->disk('local'); $this->request = $request; $this->setup($config); }
/** * @param \Illuminate\Contracts\Filesystem\Factory $storage * * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ public function export(\Illuminate\Contracts\Filesystem\Factory $storage) { $user = Auth::user(); $user->load('talks.revisions'); $headers = ['Content-type' => 'application/json']; $tempName = sprintf('%d_export.json', $user->id); $exportName = sprintf('export_%s.json', date('Y_m_d')); $export = ['talks' => $user->talks->toArray()]; $storage->disk('local')->put($tempName, json_encode($export)); $path = storage_path() . '/app/'; return response()->download($path . $tempName, $exportName, $headers)->deleteFileAfterSend(true); }
protected function deleteOrphanedFiles() { $diskName = $this->argument('disk') ?: config('laravel-medialibrary.defaultFilesystem'); if (is_null(config("filesystems.disks.{$diskName}"))) { throw FileCannotBeAdded::diskDoesNotExist($diskName); } $mediaIds = collect($this->mediaRepository->all()->pluck('id')->toArray()); collect($this->fileSystem->disk($diskName)->directories())->filter(function (string $directory) use($mediaIds) { return is_numeric($directory) ? !$mediaIds->contains((int) $directory) : false; })->each(function (string $directory) use($diskName) { if (!$this->isDryRun) { $this->fileSystem->disk($diskName)->deleteDirectory($directory); } $this->info("Orphaned media directory `{$directory}` " . ($this->isDryRun ? 'found' : 'has been removed')); }); }
/** * Renames contract filename * @param $contract * * return bool */ protected function renameS3ContractFileName($contract) { $newFileName = sprintf("%s-%s", $contract->id, $contract->Slug); $contractDir = $contract->id; $from = sprintf("%s/%s", $contractDir, $contract->file); $to = sprintf("%s/%s.pdf", $contractDir, $newFileName); if (!$this->storage->disk('s3')->move($from, $to)) { return false; } list($filename, $ext) = explode('.', $contract->file); $wordFileName = sprintf('%s.docx', $filename); $wordFileFrom = sprintf("%s/%s", $contractDir, $wordFileName); $wordFileTo = sprintf("%s/%s.docx", $contractDir, $newFileName); if (!$this->storage->disk('s3')->move($wordFileFrom, $wordFileTo)) { return false; } return true; }
public function getAwss3(Factory $factory) { $factory->disk('s3')->put('test2.txt', 'aws3 - I am using aws s3'); return 'done'; }
/** * @param $filename * @return bool */ private function fileExists($filename) { return $this->filesystem->disk($this->getConfiguredFilesystem())->exists($filename); }
public function storeImage(Requests\ProductImageRequest $request, $id, ProductImage $productImage, \Illuminate\Contracts\Filesystem\Factory $storage, \Illuminate\Filesystem\Filesystem $fileSystem) { $file = $request->file('image'); $extension = $file->getClientOriginalExtension(); $image = $productImage::create(['product_id' => $id, 'extension' => $extension]); $storage->disk('public_local')->put($image->id . '.' . $extension, $fileSystem->get($file)); return redirect()->route('admin.products.images.index', ['id' => $id]); }
/** * Constructor. * * @param SentryService $sentry * @param Factory $storage */ public function __construct(SentryService $sentry, Factory $storage) { $this->sentry = $sentry; $this->storage = $storage->disk($this->model()->getDisk()); }
/** * Bind instances to the class. * * @param \Illuminate\Contracts\Filesystem\Factory $storage */ public function __construct(Factory $storage) { $this->storage = $storage->disk('logs'); }
/** * @param DiskAdapter $adapter */ public function addAdapter(DiskAdapter $adapter) { $name = $adapter->getName(); $adapter->setFilesystem($this->filesystem->disk($name)); $this->adapters[$name] = $adapter; }
/** * Retrieve filesystem * @param array $library * @return Illuminate\Contracts\Filesystem\Filesystem */ protected function getFilesystem($library) { $storage = $library['description']['is_moved'] ? $library['description']['storage'] : 'local'; return $this->filesystemFactory->disk($storage); }
public function __construct(Filesystem $filesystem) { $this->disk = $filesystem->disk(config('filesystems.default')); }
/** * Set disk. * * @param string $disk */ public function setDisk($disk) { $this->disk = $this->files->disk($disk); }