Skip to content

Instantly share code, notes, and snippets.

@herquiloidehele
Created June 13, 2021 17:04
Show Gist options
  • Select an option

  • Save herquiloidehele/91dccc8f30b56174d348cbb192658088 to your computer and use it in GitHub Desktop.

Select an option

Save herquiloidehele/91dccc8f30b56174d348cbb192658088 to your computer and use it in GitHub Desktop.
<?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