Questo mi sta facendo impazzire: ho lavorato su questo problema per diversi giorni con scarso successo. Ho finalmente colpito un muro di mattoni e ho bisogno di aiuto. Molti degli articoli e dei forum che ho cercato non sono per AWSSDK per PHP 2.Caricamento di un'immagine tramite AWS SDK per PHP 2
Abbiamo utilizzato S3 di Amazon per caricare immagini tramite iOS negli ultimi due anni.
Ora, ho bisogno di implementare il caricamento in un browser.
Ho scaricato e installato con successo AWSSDK per PHP 2 sul nostro server Ubuntu. Posso collegarmi al nostro account AWS S3 e visualizzare il contenuto dei bucket. Ma non riesco a mettere un'immagine in un secchio.
L'eccezione da AWS è:
Aws \ S3 \ Exception \ NotImplementedException: AWS Codice di errore: NotImplemented, Codice di stato: 501, AWS Request ID: CEDC4BBAA83CF70C, AWS Il tipo di errore del server, il messaggio di errore AWS: Un colpo di testa che si fornito implica funzionalità che non è implementata.
Ecco l'URL che ho ottenuto il codice di esempio riportato di seguito da, sotto il titolo chiamato caricamento di un file di Amazon S3: https://github.com/aws/aws-sdk-php#quick-start
E ho aggiornato il mio codice in base a questo: AWS PHP SDK Version 2 S3 putObject Error
Ma ancora non funziona
Ecco il mio codice:
<?php
require_once("../config.php"); //local config vars
require_once('AWSSDKforPHP/aws.phar');
use Aws\S3\S3Client;
use Aws\Common\Enum\Region;
use Aws\Common\Aws;
use Aws\S3\Enum\CannedAcl;
use Aws\S3\Exception\S3Exception;
use Guzzle\Http\EntityBody;
//get the $s3 object
$config = array(
'key' => AMAZON_ACCESS_KEY,
'secret' => AMAZON_ACCESS_SECRET,
'region' => Region::US_EAST_1
);
$s3 = S3Client::factory($config);
try {
$bucketname = 'my_bucket_name'; //my bucket name on s3
$filename = 'filename.jpg'; //my image on my server
$path = 'http://my.website.com/app/cache/remote'; //the path where the image is located
$fullfilename = $path."/".$filename;
//this successfully lists the contents of the bucket I am interested in
foreach ($s3->getIterator('ListBuckets') as $bucket) {
foreach ($s3->getIterator('ListObjects', array('Bucket' => $bucket['Name'])) as $object) {
if ($bucket['Name'] == $bucketname) {
echo $bucket['Name'] . '/' . $object['Key'] . PHP_EOL;
}
}
}
//HERE ME HERE, PLEASE! this is the code that throws the exception
$s3->putObject(array(
'Bucket' => $bucketname,
'Key' => $filename,
'Body' => EntityBody::factory(fopen($fullfilename, 'r')),
'ACL' => CannedAcl::PUBLIC_READ_WRITE,
'ContentType' => 'image/jpeg'
));
} catch (S3Exception $e) {
echo $e;
}
?>
Qualcuno può fornire me con un esempio in modo da poter caricare l'immagine JPG nella nostra secchio S3 utilizzando AWSSDK per PHP 2?
Risoluzione: Dalla risposta di ppostma1, ho modificato il mio codice come segue, e ora lavora:
$bucketname = 'my_bucket_name'; //must be all lowercase
$filename = 'filename.jpg'; //my image on my server
$path = 'var/www/html/root-website-folder/images/'; //the physical path where the image is located
$fullfilename = $path.$filename;
$s3->putObject(array(
'Bucket' => $bucketname,
'Key' => $filename,
'Body' => EntityBody::factory(fopen($fullfilename, 'r')),
'ACL' => CannedAcl::PUBLIC_READ_WRITE,
'ContentType' => 'image/jpeg'
));
stai usando un proxy? – ppostma1