Save uploaded files to S3 and generate a URL

This commit is contained in:
Jonny Barnes 2017-03-10 09:58:35 +00:00
parent bd57ce56d4
commit 2c5c6e7753
4 changed files with 23 additions and 14 deletions

View file

@ -258,7 +258,7 @@ class MicropubController extends Controller
if ($request->file('file')->isValid()) {
//save media
try {
$filename = Uuid::uuid4() . $request->file->extension();
$filename = Uuid::uuid4() . $request->file('file')->extension();
} catch (UnsatisfiedDependencyException $e) {
return response()->json([
'response' => 'error',
@ -267,16 +267,20 @@ class MicropubController extends Controller
], 500)
}
try {
$path = $request->file->storeAs('media', $filename, 's3');
} catch(Excetion $e) { // which exception?
$path = $request->file('file')->storeAs('media', $filename, 's3');
} catch (Exception $e) { // which exception?
return response()->json([
'response' => 'error',
'error' => 'service_unavailable',
'error_description' => 'Unable to save media to S3'
], 503)
}
$media = new Media();
$media->token = $token;
$media->path = $path;
$media->save();
return $path;
return $media->url;
}
//return URL for media