/** * @param Request $request * * @return JsonResponse|array */ public function store(Request $request, Site $site) { $this->authorize('uploadAssets', $site); $assetIds = []; list($validFiles, $errors) = $this->validateAssetUpload($request); foreach ($validFiles as $file) { $asset = new Asset(); $asset->setTitle($file->getClientOriginalName())->setType(AssetHelper::typeFromMimetype($file->getMimeType())); $assetIds[] = AssetFacade::save($asset)->getId(); AssetFacade::createVersionFromFile($asset, $file); } return count($errors) ? new JsonResponse($errors, 500) : $assetIds; }
public function upload() { $assetIds = []; list($validFiles, $errors) = $this->validateFileUpload(); foreach ($validFiles as $file) { $asset = new Asset(); $asset->setUploadedTime(new DateTime('now'))->setUploadedBy(Auth::getPerson())->setTitle($file->getClientOriginalName())->setType(AssetHelper::typeFromMimetype($file->getMimeType())); $assetIds[] = AssetFacade::save($asset)->getId(); AssetFacade::createVersionFromFile($asset, $file); } return count($errors) ? new JsonResponse($errors, 500) : $assetIds; }