jacobcyl / aliyun-oss-storage Goto Github PK
View Code? Open in Web Editor NEW阿里云OSS laravel storage Filesystem adapter, 打造Laravel最好的OSS Storage扩展.
Home Page: http://jacobcyl.github.io/Aliyun-oss-storage/
License: MIT License
阿里云OSS laravel storage Filesystem adapter, 打造Laravel最好的OSS Storage扩展.
Home Page: http://jacobcyl.github.io/Aliyun-oss-storage/
License: MIT License
请问怎么生成他有私有带签名的链接地址呢?阿里云的PHP-SDK有他的方法,不知道这个怎么弄。
这是阿里云的SDK封装好的方法:https://help.aliyun.com/document_detail/32106.html?spm=a2c4g.11186623.2.13.eYBnnW
用laravel的storage好像没有这个方法,自己写的话有什么思路?
列出全部文件不全,最多1000个文件,剩下的没有查询到
'driver' => 'oss',
'access_id' => 'xxx',
'access_key' => 'xxx',
'bucket' => xxx',
'endpoint' => 'oss-cn-hangzhou.aliyuncs.com', // OSS 外网节点或自定义外部域名
'endpoint_internal' => 'oss-cn-hangzhou-internal.aliyuncs.com', // v2.0.4 新增配置属性,如果为空,则默认使用 endpoint 配置(由于内网上传有点小问题未解决,请大家暂时不要使用内网节点上传,正在与阿里技术沟通中)
'cdnDomain' => 'p.cdn.xxx.com', // 如果isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url,如果cdnDomain未设置,则使用endpoint来生成url,否则使用cdn
'ssl' => false, // true to use 'https://' and false to use 'http://'. default is false,
'isCName' => true, // 是否使用自定义域名,true: 则Storage.url()会使用自定义的cdn或域名生成文件url, false: 则使用外部节点生成url
'debug' => false
AliOssAdapter : 428
/**
* {@inheritdoc}
*/
public function readStream($path)
{
$result = $this->readObject($path);
$result['stream'] = $result['raw_contents'];
rewind($result['stream']);
// Ensure the EntityBody object destruction doesn't close the stream
$result['raw_contents']->detachStream();
unset($result['raw_contents']);
return $result;
}
其中 raw_contents 是 string
使用Storage::('oss')->get($path)时不时的会返回异常数据,当我获取文件内容时。有时候正常,有时候不正常。
异常数据:
ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Symfony\Component\Filesystem\Exception\FileNotFoundException' not found
/**
* 检验bucket名称是否合法
* bucket的命名规范:
* 1. 只能包括小写字母,数字
bucket是有‘-’和‘/’的,这个验证是不是有问题
在配置项中,有
ssl = true/false 的配置
但是在实际代码中(AliOssServiceProvider:42),是从$app['request']->secure()获取的。
这在正式环境是理论上是没有问题的。
但是在开发环境下,可能会出现问题,因为CDN设置很可能只接受https请求。
但是开发环境往往又只是http请求。
在laravel5.3中使用时putFile方法时会报错。
下面是5.3中FilesystemAdapter.php中putFile方法
public function putFile($path, $file, $visibility = null) { return $this->putFileAs($path, $file, $file->hashName(), $visibility); }
其中第二个参数是UploadedFile类型,而文档中写的是传string类型
Aliyun-oss-storage/src/AliOssAdapter.php
Line 507 in 9abd13b
修改为:
return $this->normalizeResponse($objectMeta, $path);
`
不然的话文件类型往下执行就识别成文件夹类型了;删除多个远程文件时会出现操作成功,但却只删除一个文件,原因就是把文件类型识别成了文件夹了。
因put时需先检验是否存在,导致超时报错
现在不支持上传成功后,直接获取url吗?
按照文档安装了package后,使用\Storage::disk('oss')后,报错。
[ErrorException]
Undefined index: debug
不知道这是怎么一回事?谢谢了
如题
建议添加ECS访问的内网Endpoint,如果设置内网Endpoint,则由内网Endpoint(oss-cn-hangzhou-internal.aliyuncs.com)上传,外网Endpoint(oss-cn-hangzhou.aliyuncs.com)下载。如果未添加内网Endpoint,全部由外网Endpoint上传、下载。
环境laravel5.5
Storage::disk('oss')->putFile($filename, storage_path('app/public/文件名')))
所有Storage类的调用都会报错
OssException in OssClient.php line 2187:
RequestCoreException: cURL resource: Resource id #438; cURL error: Failed to connect to xxx-internal.aliyuncs.com port 80: Connection timed out (7)
上传文件时,只要是docx pptx后缀的文件类型,上传成功后都会变成zip类型的压缩文件,其他类型的文件都是正常的
读取私有bucket下的图片,会报错,公共读的bucket没有问题
为adaptor新增signUrl方法, 以便生成带签名的地址。我目前的做法是继承你的adaptor, 新增
public function signUrl($path, $timeout = 60, $method = OssClient::OSS_HTTP_GET, $options = NULL) {
return $this->client->signUrl($this->bucket, $path, $timeout, $method, $options);
}
方法, 然后重写provider, 用自己的adaptor。
由于官方OSS PHP SDK 没有封装上传回调接口,所以打算以插件形式封装一个上传回调注册接口,大家有什么好的方案。
不知道现在上传之后,是否支持阿里云oss api的callback回调?
Previously was fine but today when I'm tried to upload / delete, I receive this type of error:
OSS\Core\OssException: RequestCoreException: cURL resource: Resource id #393; cURL error: Resolving timed out after 10531 milliseconds (28) in /var/www/monsterpress/vendor/aliyuncs/oss-sdk-php/src/OSS/OssClient.php:2187
作者你好,我们在项目中使用你的代码,但方法只返回了true和false,错误的时候记录日志(我们项目是分布式的,本机日志不太适应),我们需要在失败的时候知道错误详情,是否能在方法中直接将异常抛出呢?新建一个Tag给我们使用,不胜感激!
在大多数能引发OssException的地方,都被Catch,然后简单的return false了。
但是这样在项目运行时,可能会引发一些潜在问题。
另外:在listContents方法中,调用了listDirObjects,但是当listDirObjects发生错误时,没有做异常判定。导致异常抛出。
不捕获OssException是不是更好一些?
public function getUrl( $path )
{
if (!$this->has($path)) throw new FileNotFoundException($filePath.' not found'); //这句报错了,FileNotFoundException没有找到 2$filePath 没有定义
return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/');
}
已经有其他pull requests修复了部分bug,但都没有merge进来
另外:
Storage::disk(env('FILESYSTEM_CLOUD','local'))->putFile('path', 'path');
这个方法报错,都应该是adapter的问题。
如果有其他任何更好的库可以使用,请各位贴出来
在Laravel中使用\Storage::url(),为何要判断文件是否存在?在输出大量图片URL的循环中,严重拖慢了速度!!!而且这里,抛异常也写错了变量名啊。
public function getUrl( $path ) { if (!$this->has($path)) throw new FileNotFoundException($filePath.' not found'); return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endpoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/'); }
如
getAdapter()->getClient()->setTimeout(0);
建议用魔术方法驱动,然后注释method以便IDE提示
用Storage::url(); 获取私有云的文件地址,异常提示文件不存在FileNotFoundException
比如没有apk
形如:Images/store/lejRej//164722sy84snndg8a0pnsm.jpg
我修改配置如下之后网站就挂了:
'cdnDomain' => ‘my_cdn_domain',
'isCName' => true,
oss的CDN在ali上已经配好了,请问这里要怎么做呢?
OssException In OssClient.php line 1994 :
RequestCoreException: cURL resource: Resource id #350; cURL error: Connection timed out after 10073 milliseconds (28)
getURL方法,bucket和endPoint之间少了“.” 而且用内网域名时候链接不可用
比如以下情况:
OSS只绑定了一个域名(且开启CDN), 这时候如果开启isCName, 则endpoint必须填写为 cname域名, 否则上传出错,
而endpoint填写为 cname域名, 会导致上传也走cdn,
在我的 ImageController 里,使用如下代码的时候
$url = Storage::getUrl($path);
dd($url);
得到了一个错误的提示
Call to undefined method League\Flysystem\Filesystem::getUrl
AliOssAdapter 有些方法可以访问,有些却不行。
比如我将 AliOssAdapter 里的方法 getSize($path)
改写为如下
public function getSize($path)
{
return $path;
}
然后在我的 ImageController 里
$url = Storage::getSize($path);
dd($url);
然后又能够 dd,这就说明使用 getSize 方法的时候,已经进入了 AliOssAdapter 的 getSize 方法。
那为什么AliOssAdapter 的 getUrl 方法却无法使用呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.