Created
June 13, 2021 17:04
-
-
Save herquiloidehele/91dccc8f30b56174d348cbb192658088 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers\Api; | |
| use App\Http\Controllers\Controller; | |
| use Aws\S3\S3Client; | |
| use Aws\S3\Exception\S3Exception; | |
| use Illuminate\Http\Request; | |
| use Illuminate\Support\Facades\Input; | |
| use Illuminate\Support\Facades\Storage; | |
| class GeneralController extends Controller | |
| { | |
| private function createClient() | |
| { | |
| return new S3Client([ | |
| 'version' => 'latest', | |
| 'region' => $_SERVER['AWS_DEFAULT_REGION'] ?? env('AWS_DEFAULT_REGION') | |
| ]); | |
| } | |
| public function uploadImages(Request $request){ | |
| $resultURLs = []; | |
| foreach (Input::allFiles() as $file) { | |
| try { | |
| $resultURLs [] = Storage::put('images', $file); | |
| \Log::info('Upload Complete'); | |
| error_log('Upload Complete '); | |
| } catch (S3Exception $ex) { | |
| \Log::error($ex); | |
| error_log($ex); | |
| return response()->json(['message' => 'Erro ao fazer Upload', 'error' => $ex->getMessage()], 400); | |
| } | |
| } | |
| return response()->json(['images' => $resultURLs]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment