Giter VIP home page Giter VIP logo

flysystem-oss's Introduction

感谢关注「GitHub 热门」公众号,带你了解技术圈内热门新鲜事!

flysystem-oss's People

Contributors

bddbnet avatar chenkby avatar chibt avatar fenyoyo avatar ihipop avatar iidestiny avatar iwisen avatar jimchenwyu avatar jxlwqq avatar liujiajia avatar miaotaizi avatar smartymoon avatar stylecibot avatar tourze avatar zxdstyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flysystem-oss's Issues

阿里云官网给的PHP的OSS直传签名的时间算法是错的

public function gmt_iso8601($time)
{
$dtStr = date('c', $time);
$myDatetime = new DateTime($dtStr);
$expiration = $myDatetime->format(DateTime::ISO8601);
$pos = strpos($expiration, '+');
$expiration = substr($expiration, 0, $pos);
return $expiration.'Z';
}

比实际时间晚了8个小时,他生成0时区的算法就是把当前时间表示时区的部分裁剪掉然后强制改成0时区,所以真正的ticket过期时间是8小时以后

具体分析: https://blog.ihipop.info/2020/08/5260.html

前端直传参数错误

  1. 阿里云oss前端直传的access_id的参数名是OSSAccessKeyId, 不是accessid,这个是很明显没有测试导致的bug
  2. 回调的 callbackBody 写死,不支持自定义参数

安装后报错请问如何解决

  • php7.2,laravel 5.8 版本安装,安装方法如下
composer require "iidestiny/laravel-filesystem-oss:2.0" --ignore-platform-reqs
  • 可以安装成功,安装后访问项目报如下错误
Deprecated: Return type of Illuminate\Container\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice   /vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1214
  • 请问当前环境下如何使用这个包呢?

window设置prefix时路径错误

$prefix = 'flysystem-oss/ddd/aaa/';

$flysystem->write('file2.md', 'contents');

在windows下执行,上传到oss的文件路径为
 "oss://flysystem-oss/ddd/aaa\file2.md"

$this->prefixer = new PathPrefixer($prefix, DIRECTORY_SEPARATOR);

$this->prefixer = new PathPrefixer($prefix, '/');

修改后windows上传oss路径正常

麻烦添加setVisibility方法,便于设置文件的读取权限

大佬,可以更新下OssAdapter.php添加一个setVisibility方法,便于设置某个文件的权限吗?

<?php
namespace Iidestiny\Flysystem\Oss

……
use League\Flysystem\AdapterInterface;
……
class OssAdapter extends AbstractAdapter
{
   ……
  /**
     * {@inheritdoc}
     */
    public function setVisibility($path, $visibility)
    {
        $object = $this->applyPathPrefix($path);
        $acl = ( $visibility === AdapterInterface::VISIBILITY_PUBLIC ) ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;

        $this->client->putObjectAcl($this->bucket, $object, $acl);

        return compact('visibility');
    }
   ……
}

拼 host 逻辑存在bug,当endpoint以 `scheme://` 开头

/**
* normalize Host.
*
* @return string
*/
protected function normalizeHost()
{
if ($this->isCName) {
$domain = $this->endpoint;
} else {
$domain = $this->bucket.'.'.$this->endpoint;
}
if (0 !== stripos($domain, 'https://') && 0 !== stripos($domain, 'http://')) {
$domain = "http://{$domain}";
}
return rtrim($domain, '/').'/';
}

但在阿里云 oss sdk 中,
https://github.com/aliyun/aliyun-oss-php-sdk/blob/339a4021da5e763eaa967bd7f67357b7061a3962/src/OSS/OssClient.php#L2532

    /**
     * Checks endpoint type and returns the endpoint without the protocol schema.
     * Figures out the domain's type (ip, cname or private/public domain).
     *
     * @param string $endpoint
     * @param boolean $isCName
     * @return string The domain name without the protocol schema.
     */
    private function checkEndpoint($endpoint, $isCName)
    {
        $ret_endpoint = null;
        if (strpos($endpoint, 'http://') === 0) {
            $ret_endpoint = substr($endpoint, strlen('http://'));
        } elseif (strpos($endpoint, 'https://') === 0) {
            $ret_endpoint = substr($endpoint, strlen('https://'));
            $this->useSSL = true;
        } else {
            $ret_endpoint = $endpoint;
        }
        if ($isCName) {
            $this->hostType = self::OSS_HOST_TYPE_CNAME;
        } elseif (OssUtil::isIPFormat($ret_endpoint)) {
            $this->hostType = self::OSS_HOST_TYPE_IP;
        } else {
            $this->hostType = self::OSS_HOST_TYPE_NORMAL;
        }
        return $ret_endpoint;
    }

endpoint 还承载了是否开启 https 的作用。而当前插件在 OSS_IS_CNAME 为 false 时,自动的将 bucket 名字拼接到 endpoint 前,就产生了问题。

image

getUrl 方法没有处理前缀导致获取url错误

这是目前的代码,处理完host就直接拼接了 $path,导致假如有设置 root的情况下,该方法返回了错误的url

public function getUrl($path)
    {
        return $this->normalizeHost().ltrim($path, '/');
    }

应该改为如下:

public function getUrl($path)
    {
        $path = $this->applyPathPrefix($path);

        return $this->normalizeHost().ltrim($path, '/');
    }

Driver [oss] is not supported.

将 oss 配置 添加到 filesystems.php 依旧是报错

 'oss' => [
            'driver' => 'oss',
            'access_key' => env('OSS_ACCESS_KEY'),
            'secret_key' => env('OSS_SECRET_KEY'),
            'endpoint'   => env('OSS_ENDPOINT'),
            'bucket'     => env('OSS_BUCKET'),
            'isCName'    => env('OSS_IS_CNAME', false), // 如果 isCname 为 false,endpoint 应配置 oss 提供的域名如:`oss-cn-beijing.aliyuncs.com`,否则为自定义域名,,cname 或 cdn 请自行到阿里 oss 后台配置并绑定 bucket
        ],

deleteDir和createDir可以折中实现,麻烦看看是否可以优化

大佬,关于deleteDircreateDir可以采用以下方式实现,能否帮忙完善一下?我提交PR错误后一直检测不通过

     /**
     * Delete a directory.
     *
     * @param string $dirname
     *
     * @return bool
     */
    public function deleteDir($dirname)
    {
        $fileList = $this->listContents($dirname,true);
        foreach($fileList as $file){
            $this->delete($file['path']);
        }
        return !$this->has($dirname);
    }

    /**
     * create a directory.
     *
     * @param string $dirname
     * @param Config $config
     *
     * @return bool
     */
    public function createDir($dirname, Config $config)
    {
        $defaultFile = trim($dirname, '/') . '/oss.txt';

        return $this->write($defaultFile, '当虚拟目录下有其他文件时,可删除此文件~', $config);

    }

read from oss add prefix

public function readStream(string $path)
{
$stream = fopen('php://temp', 'w+b');
$path = $this->prefixer->prefixPath($path);
try {
fwrite($stream, $this->client->getObject($this->bucket, $path, [OssClient::OSS_FILE_DOWNLOAD => $stream]));
} catch (OssException $exception) {
fclose($stream);
throw UnableToReadFile::fromLocation($path, $exception->getMessage());
}
rewind($stream);

    return $stream;
}

前端直传添加自定义字段的问题.

在获取签名的时候, 设置自定义字段 回调的时候为什么收不到值?

有人遇到这个情况吗.

OSS 官方文档的描述 :

发起回调时请求 body 的值,例如:key=$(object)&etag=$(etag)&my_var=$(x:my_var)。
支持 OSS 系统变量、自定义变量和常量,支持的系统变量如下表所示 。自定义变量的支持方式在 PutObject 和CompleteMultipart 中是通过 callback-var 来传递,在 PostObject中则是将各个变量通过表单域来传递。

这个 PostObject 中的各个变量表单域是啥????

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.