コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 public function createFile(array $data)
 {
     // name, description, extension, file
     $project = $this->repository->skipPresenter()->find($data['project_id']);
     $projectFile = $project->files()->create($data);
     $this->storage->put($data['name'] . "." . $data['extension'], $this->fileSystem->get($data['file']));
 }
コード例 #3
0
 public function restore($id, Filesystem $storage)
 {
     $photo = Photo::withTrashed()->find($id);
     $deletedFile = "uploads/photos/deleted/" . $photo->filename;
     $storage->move($deletedFile, "uploads/photos/" . $photo->filename);
     return $photo->restore();
 }
コード例 #4
0
 public function createFile(array $data)
 {
     $project = $this->repository->skipPresenter()->find($data['project_id']);
     //dd($project);
     $projectFile = $project->files()->create($data);
     $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file']));
 }
コード例 #5
0
ファイル: BuildSiteMap.php プロジェクト: hughgrigg/ching-shop
 /**
  * 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));
 }
コード例 #6
0
 private function getBaseUrl($projectFile)
 {
     switch ($this->storage->getDefaultDriver()) {
         case 'local':
             return $this->storage->getDriver()->getAdapter()->getPathPrefix() . '/' . $projectFile->id . '.' . $projectFile->extension;
     }
 }
 /**
  * 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;
 }
コード例 #8
0
 public function showFile($id, $idFile)
 {
     $model = $this->repository->skipPresenter()->find($idFile);
     $filePath = $this->service->getFilePath($idFile);
     $fileContent = file_get_contents($filePath);
     $file64 = base64_encode($fileContent);
     return ['file' => $file64, 'size' => filesize($filePath), 'name' => $this->service->getFileName($idFile), 'mime_type' => $this->storage->mimeType($model->getFileName())];
 }
コード例 #9
0
 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();
     }
 }
コード例 #10
0
 public function fetchFile(Storage $storage, $file)
 {
     if (!$storage->exists($file)) {
         return abort(404);
     }
     $locationRoot = $storage->getDriver()->getAdapter()->getPathPrefix();
     return response()->download($locationRoot . $file);
 }
コード例 #11
0
ファイル: Receiver.php プロジェクト: inoplate/media
 /**
  * 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);
 }
コード例 #12
0
ファイル: FileService.php プロジェクト: swyong/Media
 /**
  * @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;
 }
コード例 #13
0
 /**
  * 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;
 }
コード例 #14
0
 /**
  * Register the package drivers.
  *
  * @return void
  */
 protected function registerDrivers()
 {
     $this->factory->extend('ftp', function ($app, $config) {
         return new Filesystem(new FtpAdapter($config));
     })->extend('sftp', function ($app, $config) {
         return new Filesystem(new SftpAdapter($config));
     })->extend('zip', function ($app, $config) {
         return new Filesystem(new ZipAdapter($config['path']));
     });
 }
コード例 #15
0
 /**
  * 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']);
     }
 }
コード例 #16
0
 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'];
         }
     }
 }
コード例 #17
0
 /**
  * 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();
 }
コード例 #18
0
 /**
  * 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 '';
 }
コード例 #19
0
ファイル: RuntimeResizer.php プロジェクト: inoplate/media
 /**
  * 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());
 }
コード例 #20
0
ファイル: AppServiceProvider.php プロジェクト: pmall/enyofs
 public function registerGridfsFilesystem(FilesystemManager $filesystem)
 {
     $filesystem->extend('gridfs', function ($app, $config) {
         $fs_host = $config['host'];
         $fs_port = $config['port'];
         $fs_database = $config['database'];
         $mongo = new MongoClient('mongodb://' . $fs_host . ':' . $fs_port);
         $db = $mongo->selectDB($fs_database);
         $gridfs = $db->getGridFS();
         return new Filesystem(new GridFSAdapter($gridfs));
     });
 }
コード例 #21
0
 /**
  * @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);
 }
コード例 #22
0
 /**
  * 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);
 }
コード例 #23
0
 /**
  * @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);
         }
     }
 }
コード例 #24
0
 /**
  * @param $projectId
  * @param $fileId
  * @return array|mixed
  */
 public function download($projectId, $fileId)
 {
     try {
         $model = $this->repository->skipPresenter()->find($fileId);
         $filePath = $this->service->getFilePath($fileId);
         $fileContent = file_get_contents($filePath);
         $file64 = base64_encode($fileContent);
         $fileBd = $this->repository->skipPresenter()->find($fileId);
         return ['data' => ['file' => $file64, 'size' => filesize($filePath), 'fileName' => $fileBd->getFileName(), 'name' => $fileBd->name, 'description' => $fileBd->description, 'extension' => $fileBd->extension, 'mime_type' => $this->storage->mimeType($model->getFileName())]];
     } catch (ModelNotFoundException $e) {
         return ['error' => true, 'message' => 'Não foi possível encontrar o registro'];
     } catch (\Exception $e) {
         return ["error" => true, "message" => $e->getMessage()];
     }
 }
コード例 #25
0
 /**
  * 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;
 }
コード例 #26
0
 public function delete($id)
 {
     $projectFile = $this->repository->skipPresenter()->find($id);
     if ($this->storage->exists($projectFile->getFileName())) {
         $this->storage->delete($projectFile->getFileName());
         return $projectFile->delete();
     }
     /*
     // recupera somente os Files
     $files = $this->repository->skipPresenter()->find($projectId)->files;
     //dd($files);
     $deletar = [];
     foreach ($files as $file) {
         $path = $file->id . '.' . $file->extension;
         // deletar da bd
         if($file->delete($file->id))
             $deletar[] = $path;
     }
     //dd($deletar);
     $r = $this->storage->delete($deletar);
     if($r)
         return ['error' => false];
     else
         return ['error' => true];
     */
 }
コード例 #27
0
ファイル: Filesystem.php プロジェクト: sidis405/stillpoint
 /**
  * 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;
 }
コード例 #28
0
 /**
  * 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);
     }
 }
コード例 #29
0
 private function getBaseUrl($file)
 {
     switch ($this->storage->getDefaultDriver()) {
         case 'local':
             return $this->storage->getDriver()->getAdapter()->getPathPrefix() . '/' . $file->file;
     }
 }
コード例 #30
0
 /**
  * @param $projectFile
  * @return string
  */
 public function getBaseUrl($projectFile)
 {
     switch ($this->storage->getDefaultDriver()) {
         case 'local':
             return $this->storage->getDriver()->getAdapter()->getPathPrefix() . '/' . $projectFile->getFileName();
     }
 }