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'])); }
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'])); }
public function update($projectId, $fileId, $file, array $data) { try { if (is_null($file)) { $this->validator->setRules(['name' => 'required|max:255', 'description' => 'required']); $this->validator->with($data)->passesOrFail(); $fileUpdate = $this->repository->findWhere(['project_id' => $projectId, 'id' => $fileId])->first(); $fileUpdate->update($data, $fileId); return $this->find($projectId, $fileUpdate->id); } $this->validator->with($data)->passesOrFail(); $fileUpdate = $this->repository->findWhere(['project_id' => $projectId, 'id' => $fileId])->first(); $data['extension'] = $file->getClientOriginalExtension(); $data['file'] = md5(date('Y-m-d H:i:s')) . "." . $data['extension']; $this->storage->put($data['file'], $this->filesystem->get($file)); if ($this->storage->exists($fileUpdate->file)) { $this->storage->delete($fileUpdate->file); } $fileUpdate->update($data, $fileId); return $this->find($projectId, $fileUpdate->id); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } catch (\Exception $e) { return ['error' => true, 'message' => $e->getMessage()]; } }
public function createFile(array $data) { try { $this->validator->with($data)->passesOrFail(); $this->storage->put($data['name'] . '.' . $data['extension'], $this->filesystem->get($data['file'])); return $this->repository->create($data); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function createFile($data) { try { $this->validator->with($data)->passesOrFail(); $project = $this->projectRepository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $this->storage->put($projectFile->getFileName(), $this->filesystem->get($data['file'])); return $projectFile; } catch (ValidatorException $e) { return ["sucess" => false, "message" => $e->getMessageBag()]; } }
public function create(array $data) { try { $this->validator->with($data)->passesOrFail(); $project = $this->projectRepository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $this->storage->put($projectFile->id . "." . $data['extension'], $this->fileSystem->get($data['file'])); return $projectFile; } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function create(array $data) { try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE); $projeto = $this->projetoRepository->skipPresenter()->find($data['projeto_id']); $projetoFile = $projeto->files()->create($data); $this->storage->put($projetoFile->getFileName(), $this->filesystem->get($data['file'])); return $projetoFile; } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function createFile(array $data) { try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE); $project = $this->projectRepository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file'])); return $projectFile; } catch (ValidatorException $ev) { return ['error' => true, 'message' => $ev->getMessageBag()]; } catch (ModelNotFoundException $e) { return ['error' => true, 'message' => 'Projeto não localizado']; } }
public function createFile(UploadedFile $file, array $data) { try { $this->projectFileValidator->with($data)->passesOrFail(); $extension = $file->getClientOriginalExtension(); $data['extension'] = $extension; $project = $this->repository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $this->storage->put($projectFile->id . '.' . $extension, $this->filesystem->get($file)); return ['success' => true, 'message' => 'Arquivo enviado com sucesso!']; } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function create(array $data) { try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE); #dd($this->filesystem->get($data['file'])); $file = $this->repository->skipPresenter()->create($data); #dd($file['data']['id']); #$file = new \stdClass(); #$file->id = 1; #$this->storage->put( $file['data']['id'].'.'.$data['extension'], $this->filesystem->get($data['file']) ); $this->storage->put($file->getFileName(), $this->filesystem->get($data['file'])); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
/** * upload file * @param [type] $file [description] * @return [type] [description] */ public function saveFile($file) { $this->setFile($file); $filename = $this->fileName; $ext = $this->fileExtension; $directory = $this->folder; $path = Path::tidy($directory . '/' . $filename . '.' . $ext); $maxFileSize = config('finder.max_file_size'); if (filesize($this->pathToFile) > $maxFileSize) { throw new FileTooBig('File too large, file size should not be more than ' . File::getHumanReadableSize($maxFileSize)); } $allowedExtensions = config('finder.allowed_extensions'); if (!in_array($ext, $allowedExtensions)) { $message = "{$filename}.{$ext} has an invalid extension. Valid extension(s): " . implode(', ', $allowedExtensions); throw new FileNotAllowed($message); } // If the file exists, we'll append a timestamp to prevent overwriting. if ($this->fileSystem->exists($path)) { $basename = $filename . '-' . time() . '.' . $ext; $path = Path::assemble($directory, $basename); } $path = Str::removeLeft($path, '/'); $content = file_get_contents($this->pathToFile); if ($this->fileSystem->put($path, $content)) { return $this->fileDetails($path); } return false; }
public function create(array $data) { // diversos serviços // enviar email // disparar notificacao try { //dd($data); $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE); $project = $this->projectRepository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $this->storage->put($projectFile->getFileName(), $this->filesystem->get($data['file'])); return $projectFile; } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function createFile($request) { $project = $this->repository->skipPresenter()->find($request->project_id); $file = $request->file('file'); $extension = $file->getClientOriginalExtension(); $projectFile = $project->files()->create(['name' => $request->name, 'extension' => $extension, 'description' => $request->description, 'project_id' => $request->project_id]); $this->storage->put($projectFile->id . '.' . $extension, $this->file->get($file)); }
public function update(array $data, $fileId) { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_UPDATE); if ($data['file'] != NULL) { $this->storage->put($fileId . "." . $data['extension'], $this->fileSystem->get($data['file'])); } else { unset($data['file']); unset($data['extension']); } if (empty($data['name'])) { unset($data['name']); } if (empty($data['description'])) { unset($data['description']); } return $this->repository->update($data, $fileId); }
public function createFile(array $data) { if ($projectid = $this->repository->find($data->project_id) == null) { return "projeto nao existe"; } else { $project = $this->repository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); return $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file'])); } }
/** * @param array $data * @param $file * @param $idProject * @return array|mixed */ public function create(array $data, $file, $idProject) { try { $data['project_id'] = $idProject; $data['extension'] = $file->getClientOriginalExtension(); $data['size'] = $file->getClientSize(); $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE); if ($data['size'] > $this->sizeMax) { throw new ValidatorException('O arquivo enviado é muito grande, envie arquivos de até 2MB.'); } $projectFile = $this->repository->skipPresenter()->create($data); $this->storage->put($projectFile->getFileName(), $this->fileSystem->get($file)); return $this->repository->find($projectFile->id); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } catch (\Exception $e) { return ["error" => true, "message" => $e->getMessage()]; } }
public function create(Request $request, Filesystem $storage) { $filename = str_random(10) . time() . "." . $request->file('photo_file')->getClientOriginalExtension(); $storage->put('uploads/photos/' . $filename, \File::get($request->file('photo_file'))); $input = $request->input(); $newPhoto = new Photo(); $newPhoto->photo_name = $input['photo_name']; $newPhoto->photo_description = $input['photo_description']; $newPhoto->filename = $filename; $newPhoto->album_id = $input['album_id']; return $newPhoto->save(); }
public function createFile(array $data) { try { $this->validator->with($data)->passesOrFail(); $project = Project::find($data['project_id']); if (is_null($project)) { return Errors::invalidId($data['project_id']); } $user_id = \Authorizer::getResourceOwnerId(); if (!$this->projectRepository->isMember($data['project_id'], $user_id)) { return Errors::basic('Acesso negado. Você não é membro do projeto selecionado.'); } $data['extension'] = $data['file']->getClientOriginalExtension(); $projectFile = $this->repository->create($data); $nome = $projectFile->id . "." . $data['extension']; $arquivo = $this->filesystem->get($data['file']); $this->storage->put($nome, $arquivo); return ['message' => 'Arquivo criado']; } catch (ValidatorException $e) { return Errors::basic($e->getMessageBag()); } }
public function createFile(array $data) { try { $project = $this->repository->find($data['project_id']); $project->files()->create($data); } catch (\Exception $e) { //throw new ServiceException('Não foi possível gravar o arquivo no banco de dados.'); throw new ServiceException($e->getMessage()); } try { $this->storage->put($data['name'] . "." . $data['extension'], $this->filesystem->get($data['file'])); return ['message' => 'File upload successfully']; } catch (\Exception $e) { throw new ServiceException($e->getMessage()); } }
public function createFile(array $data) { try { //$this->fileValidator->with($data)->passesOrFail(); //utilizando o mesmo repository do project //utilizando o skipPresenter ele retorna o array $project = $this->repository->skipPresenter()->find($data['project_id']); // dd($project); $projectFile = $project->files()->create($data); //Storeage facede que executa o metodo put, cria o arquivo com o nome e extensiion //File face que faz upload $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file'])); if ($this->storage->exists($projectFile->id . "." . $data['extension'])) { return response()->json($projectFile->name . " up success !!"); } } catch (ValidatorException $e) { return response()->json(['error' => true, 'message' => $e->getMessageBag()]); } }
public function createFile(Request $request, $project_id) { try { $info = $request->all(); $info['project_id'] = $project_id; $this->fileValidator->with($info)->passesOrFail(); $file = $request->file('file'); $extension = $file->getClientOriginalExtension(); $data['file'] = $file; $data['extension'] = $extension; $data['name'] = $request->name; $data['project_id'] = $project_id; $data['description'] = $request->description; $project = $this->repository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file'])); return ['error' => false, 'message' => 'success']; } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
/** * @return mixed */ protected function upload() { $this->storage->put($this->fullPath(), $this->fileContents, $this->acl); return $this; }