Solo queriendo publicar una contribución a esto, Alex Neth tiene razón en esta referencia, pero no creo que un enlace sea información suficiente, utilizando AWS PHP SDK2 de Amazon. A continuación, describí un método básico (no probado) para llamar a los datos de esta manera, puede usar el Método de fábrica S3 o el Creador de servicios de AWS para crear el Cliente S3.
<?php
// S3 Factory Method
/*use Aws\S3\S3Client;
$s3= S3Client::factory(array(
'key' => '<aws access key>',
'secret' => '<aws secret key>'
));*/
// OR AWS Service Builder
use Aws\Common\Aws;
// Create a service builder using a configuration file
$aws = Aws::factory('/path/to/my_config.json');
// Get the client from the builder by namespace
$s3 = $aws->get('S3');
// Now lets create our request object.
$command = $s3->getCommand('GetObject',array(
'Bucket' => 'your-bucket-name',
'Key' => 'keyname',
'ResponseContentType' => 'application/octet-stream',
'ResponseContentDisposition' => 'attachment; filename="filename.mp3',
));
$url = $command->createPresignedUrl('+1 days');
?>
Puede utilizar el encabezado de PHP ("Ubicación: $ url"); para redirigir al visitante al archivo MP3 con una descarga forzada, esto debería evitar que se reproduzca en el navegador. Tenga en cuenta que utilizo ResponseContentType con bastante frecuencia pero nunca he usado ResponseContentDisposition con AWS (debería funcionar de acuerdo con los documentos).)
conversión de esta muestra en una función debe ser fácil, incluso se podría pasar en balde $, $ key, $ force_download como tal
<?php
use Aws\Common\Aws;
function gen_url($bucket,$key,$force_download=false){
// OR AWS Service Builder (personal method to do this)
// Create a service builder using a configuration file
$aws = Aws::factory('/path/to/my_config.json');
// Get the client from the builder by namespace
$s3 = $aws->get('S3');
$params = array(
'Bucket' => $bucket,
'Key' => 'keyname',
'ResponseContentType' => 'application/octet-stream',
'ResponseContentDisposition' => 'attachment; filename="filename.mp3',
);
if($force_download){
$params['ResponseContentType'] = 'application/octet-stream';
$params['ResponseContentDisposition'] = 'attachment; filename="'.basename($key).'"';
}
$command = $s3->getCommand('GetObject',$params);
return $command->createPresignedUrl('+1 days');
}
// Location redirection to an MP3 force downlaod
header("Location: ".gen_url("recordings","my-file.mp3",true));
// Location redirection to a MP3 that lets the browser decide what to do.
header("Location: ".gen_url("recordings","my-file.mp3"));
?>
ADVERTENCIA, si no se ha dado cuenta, esto requiere que el AWS PHP SDK 2 actualmente (7 de abril de 2014) se encuentra aquí http://aws.amazon.com/sdkforphp/ Este código es en su mayoría pseudocódigo y puede requerir algunos ajustes adicionales para realmente hacer el trabajo, ya que estoy haciendo referencia a esto desde la memoria.
http://stackoverflow.com/questions/2613792/amazon-s3-add-metadata- to-existing-key – andrewrk