zgldh / qiniu-laravel-storage

Qiniu 云储存 Laravel 5 Storage版
MIT License
521 stars 79 forks source link

从QiniuAdapter 中的 writeStream 跳转到 qiniuPutFile 会报错 #85

Closed buxuhunao closed 2 years ago

buxuhunao commented 2 years ago

V9.0.3版本,PHP版本8.0.14

    public function writeStream(string $path, $contents, Config $config): void
    {
        $auth = $this->getAuth();

        $token = $this->uploadToken ?: $auth->uploadToken($this->bucket, $path);
        $this->withUploadToken(null);

        $params = $config->get('params', null);
        $mime = $config->get('mime', 'application/octet-stream');
        $checkCrc = $config->get('checkCrc', false);

        $resourceData = '';
        while (!feof($contents)) {
            $resourceData = $resourceData . fread($contents, 1024);
        }

        [$ret, $error] = $this->qiniuPutFile($token, $path, $resourceData, $params, $mime, $checkCrc);

        if ($error !== null) {
            $this->logQiniuError($error);
        } else {
            $this->lastReturn = $ret;
        }
    }

private function qiniuPutFile(
        $upToken,
        $key,
        $fileResource,
        $params = null,
        $mime = 'application/octet-stream',
        $checkCrc = false
    )
    {
        if ($fileResource === false) {
            throw new \Exception("file can not open", 1);
        }
        $file = $fileResource;
        $params = UploadManager::trimParams($params);
        $stat = fstat($file);
        $size = $stat['size'];
        if ($size <= QiniuConfig::BLOCK_SIZE) {
            $data = fread($file, $size);
            fclose($file);
            if ($data === false) {
                throw new \Exception("file can not read", 1);
            }
            $result = FormUploader::put(
                $upToken,
                $key,
                $data,
                new QiniuConfig(),
                $params,
                $mime,
                basename($key)
            );
            return $result;
        }
        $up = new ResumeUploader(
            $upToken,
            $key,
            $file,
            $size,
            $params,
            $mime,
            new QiniuConfig()
        );
        $ret = $up->upload(basename($key));
        fclose($file);
        return $ret;

writeStream中的变量resourceData 为字符串,作为参数传入qiniuPutFile中,然后又把此变量作为资源传入fstat函数中导致报错。

zgldh commented 2 years ago

试试 v9.0.4

buxuhunao commented 2 years ago

试试 v9.0.4

可以了,感谢