上传发布文件到Amazon S3 [英] uploading posted file to amazon s3
问题描述
我想通过Laravel 4将文件上传到Amazon S3。
在用户提交表单,该文件将被传递给函数,我需要使用Amazon PHP SDK和上传文件到Amazon S3桶。
但我怎么上传的文件马上到Amazon S3不将文件保存到服务器上。
我目前的code是这样的,
私有函数uploadVideo($ VID){
$文件= $ VID;
$文件名= $文件 - > getClientOriginalName();
如果(class_exists('S3')!)require_once('S3.php');
如果(定义('awsAccessKey')!)限定('awsAccessKey','123123123');
如果(定义('awsSecretKey')!)限定('awsSecretKey','123123123');
$ S3 =新S3(awsAccessKey,awsSecretKey);
$ S3-> putBucket(mybucket,S3 :: ACL_PUBLIC_READ);
$ S3-> putObject($ VID,mybucket,$文件名,S3 :: ACL_PUBLIC_READ);
}
从抓斗的官方SDK <一href="http://docs.aws.amazon.com/aws-sdk-php/latest/index.html">http://docs.aws.amazon.com/aws-sdk-php/latest/index.html
本例使用<一个href="http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_upload">http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_upload
规定(aws.phar');
使用AWS \ S3 \ S3Client;
使用AWS \公用\ Enum的\地区;
//实例化S3客户端与您的AWS凭据,并希望AWS地区
$客户端= S3Client ::工厂(阵列(
'键'=&GT; 这里的关键,
秘密=&GT; 秘密这里,
'区域'=&GT;地区:: AP_SOUTHEAST_2 //你需要更改或删除此
));
$结果= $客户 - &GT;上传(
斗这里,
对象键的位置',
字符串的文件的位置,
大众阅读//公共接入访问控制列表
);
I'm trying to upload a file to Amazon S3 via Laravel 4.
After user submit a form, the file will be passed to a function where I need to use Amazon PHP SDK and upload the file to Amazon S3 bucket.
But how do I upload the file straight away to Amazon S3 without saving the file onto server.
My current code looks like this,
private function uploadVideo($vid){
$file = $vid;
$filename = $file->getClientOriginalName();
if (!class_exists('S3'))require_once('S3.php');
if (!defined('awsAccessKey')) define('awsAccessKey', '123123123');
if (!defined('awsSecretKey')) define('awsSecretKey', '123123123');
$s3 = new S3(awsAccessKey, awsSecretKey);
$s3->putBucket("mybucket", S3::ACL_PUBLIC_READ);
$s3->putObject($vid, "mybucket",$filename , S3::ACL_PUBLIC_READ);
}
Grab the official SDK from http://docs.aws.amazon.com/aws-sdk-php/latest/index.html
This example uses http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_upload
require('aws.phar');
use Aws\S3\S3Client;
use Aws\Common\Enum\Region;
// Instantiate the S3 client with your AWS credentials and desired AWS region
$client = S3Client::factory(array(
'key' => 'KEY HERE',
'secret' => 'SECRET HERE',
'region' => Region::AP_SOUTHEAST_2 // you will need to change or remove this
));
$result = $client->upload(
'BUCKET HERE',
'OBJECT KEY HERE',
'STRING OF YOUR FILE HERE',
'public-read' // public access ACL
);
这篇关于上传发布文件到Amazon S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!