Skip to content

Commit

Permalink
throw error in failed upload file
Browse files Browse the repository at this point in the history
  • Loading branch information
eucyt committed Jun 22, 2023
1 parent 3b6d142 commit a204ed6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion laravel/app/Services/PaperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Requests\StorePaperRequest;
use App\Http\Requests\UpdatePaperRequest;
use App\Models\Paper;
use Exception;
use Illuminate\Http\UploadedFile;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Storage;
Expand Down Expand Up @@ -91,12 +92,15 @@ public function unregisterPdf(Paper $paper)
* @param UploadedFile $file
* @param string $title
* @return string
* @throws Exception
*/
private function uploadPdf(UploadedFile $file, string $title)
{
$path = '/';
$pdf_name = $this->normalizeTitle($title) . '.pdf';
Storage::disk('s3')->putFileAs($path, $file, $pdf_name);
if (Storage::disk('s3')->putFileAs($path, $file, $pdf_name) === false) {
throw new Exception('PDFのアップロードに失敗しました。');
}
return config('filesystems.disks.s3.url') . '/'
. config('filesystems.disks.s3.bucket') . $path . $pdf_name;
}
Expand Down

0 comments on commit a204ed6

Please sign in to comment.