Skip to content

Instantly share code, notes, and snippets.

@acidjazz
Created August 27, 2021 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acidjazz/8572c7651b1cdf9ad426f2cfca5fbec5 to your computer and use it in GitHub Desktop.
Save acidjazz/8572c7651b1cdf9ad426f2cfca5fbec5 to your computer and use it in GitHub Desktop.
store a file to s3
<?
public function store(Request $request): Response|JsonResponse
{
$this
->option('file', 'required|file|max:10000000')
->option('type', 'nullable|in:' . Image::ABLES)
->option('id', 'nullable')
->verify();
/** @var UploadedFile $file */
$file = $request->file;
$fileName = $file->storePublicly('');
return $this->success('image.uploaded', [], [
'url' => 'https://' . config('filesystems.disks.s3.bucket') . '.s3.amazonaws.com/' . $fileName,
'file' => $fileName,
'name' => $file->getClientOriginalName(),
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment