Giter Site home page Giter Site logo

laravel-oss's Introduction

Laravel-Oss

专用于Laravel的阿里云OSS扩展包

##安装 ####添加依赖 添加

"naux/laravel-oss": "1.*"

到你的composer.json文件的require中, 执行composer installcomposer update

####注册Provider 在你的 config/app.php文件 providers数组中中添加'Naux\LaravelOss\LaravelOssServiceProvider'

####配置 执行命令php artisan config:publish naux/laravel-oss
然后到app/config/packages/naux/laravel-oss/config.php文件中按照注释修改配置。

##实例

//删除bucket foo下的bar对象
OSS::bucket('foo')->delete('bar');

//上面选择了bucket,后面的操作都不用重复

//上传请求中的文件
OSS::upload('foobar', Input::file('image'));

//取得directory目录下的所有对象信息
foreach(OSS::files('directory') as $file){
	//do something
}

##使用 ####获取原生OSSClient对象

OSS::getClient();

####选择bucket

OSS::bucket('foo');

如果在配置文件中设置了default字段,就不需要选择

####删除bucket

OSS::bucket('foo')->destroy();

####创建新的bucket

OSS::create('foo');

//创建bucket同时设置权限
OSS::create('foo', 'public');

权限选项:

  1. private私有(默认)
  2. public-read公共读
  3. public-read-write 公共读写

####获取所有bucket

//当前账号拥有的所有bucket
OSS::buckets();

####上传文件

//根据路径上传文件
OSS::upload('foobar', '/temps/file');

//上传文件,同时设置其他信息
OSS::upload('foobar', '/temps/file', [
	'Expires' => new \DateTime("+5 minutes"),
	'Content-Type' => 'foo',
	//...
]);

//上传请求中的文件
OSS::update('foobar', Input::file('foobar'));

使用Input::file()上传的文件,会被自动设置ContentType

####删除object

OSS::delete('object_key');

//同时删除多个
OSS::delete(['object_key1', 'object_key2']);

####拷贝Object

OSS::copy('from', 'to');

//从当前的bucket拷贝到其他bucket
OSS::copy('from', 'to', 'another_bucket');

####移动Object

OSS::move('from', 'to');

//从当前的bucket其他bucket并重命名
OSS::move('from', 'to', 'another_bucket');

####获取所有Object列表

OSS::objects();

//方法声明
//public function objects($start = 0, $limit = 100, $prefix = '', $delimiter = ''){}

参数 参考文档

####获取指定目录下Object列表

//获得temps目录下所有object列表
OSS::files('temps');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.