Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Route::get('dir', function()
- {
- return View::make('dir');
- });
- Route::post('dir', function()
- {
- $v = Validator::make(Input::all(), ['name' => 'required']);
- if ($v->fails()) {
- return Redirect::back()->withErrors($v);
- }
- // criar diretório 13
- $result = AWS::get('s3')->putObject([
- 'Bucket' => 'bucketName',
- 'Key' => rtrim(Input::get('name'), '/') . '/',
- 'Body' => ''
- ]);
- echo $result;
- });
- Route::get('aws', function()
- {
- return View::make('aws');
- });
- Route::post('awsupload', function()
- {
- if (Input::hasFile('file')) {
- $file = Input::file('file');
- $result = AWS::get('s3')->putObject([
- 'Bucket' => 'bucketName',
- 'Key' => "images/{$file->getClientOriginalName()}",
- 'SourceFile' => $file->getRealPath(),
- 'ACL' => \Aws\S3\Enum\CannedAcl::PRIVATE_ACCESS // Em princípio fechado
- ]);
- // TODO Salvar dados da imagem
- return Response::json(['result' => 'success', 'object' => $result->toArray()]);
- }
- return Response::json(['result' => 'error'], 500);
- });
- Route::get('s3result', function()
- {
- // Obter objetos em um diretório específico de um bucket
- /** @var \Aws\S3\S3Client $s3 */
- $s3 = AWS::get('s3');
- $objects = $s3->getIterator('ListObjects', [
- 'Bucket' => 'bucketName',
- 'Prefix' => 'images/',
- 'Delimiter' => '/'
- ]);
- $files = [];
- foreach ($objects as $o) {
- // Remover pasta (tamanho da pasta é 0)
- if ($o['Size'] == 0) {
- continue;
- }
- $clazz = new stdClass;
- $clazz->key = $o['Key'];
- // pre-signed URL Obter (URL pública temporária)
- $command = $s3->getCommand('GetObject', [
- 'Bucket' => 'smoochy',
- 'Key' => $clazz->key
- ]);
- // Obtenha um URL válido por 10 minutos
- $clazz->url = $command->createPresignedUrl('+10 minutes');
- $files[] = $clazz;
- }
- return View::make('s3result', ['files' => $files, 'objects' => $objects->toArray()]);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement