/**
  * Upload a file.
  *
  * @param  FileUploader                  $uploader
  * @param  FolderRepositoryInterface     $folders
  * @return \Illuminate\Http\JsonResponse
  */
 public function upload(FileUploader $uploader, FolderRepositoryInterface $folders)
 {
     if ($file = $uploader->upload($this->request->file('upload'), $folders->find($this->request->get('folder')))) {
         return $this->response->json($file->getAttributes());
     }
     return $this->response->json(['error' => 'There was a problem uploading the file.'], 500);
 }
Example #2
0
 /**
  * Handle the upload.
  *
  * @param FileUploader $uploader
  * @param FolderRepositoryInterface $folders
  * @return \Illuminate\Http\JsonResponse
  */
 public function upload(FileUploader $uploader, FolderRepositoryInterface $folders)
 {
     $error = trans('anomaly.module.files::error.generic');
     try {
         if ($file = $uploader->upload($this->request->file('upload'), $folders->find($this->request->get('folder')))) {
             return $this->response->json($file->getAttributes());
         }
     } catch (\Exception $e) {
         $error = $e->getMessage();
     }
     return $this->response->json(['error' => $error], 500);
 }