【问题标题】:List Azure files and folders from File share snapshots with php使用 php 从文件共享快照中列出 Azure 文件和文件夹
【发布时间】:2021-07-28 22:46:05
【问题描述】:

要列出 Azure Files 中的文件和文件夹,可以使用以下代码:

function ListFolder($shareName, $path)
{
    global $fileRestProxy;
    $vMaxResultados = 5000;
    $vNextMarker = "";
    $listResult = null;
    try
    {
        do
        {
            $options = new ListDirectoriesAndFilesOptions();
            $options->setMaxResults($vMaxResultados);
            $options->setMarker($vNextMarker);
            $listResult = $fileRestProxy->ListDirectoriesAndFiles($shareName,$path,$options);
            $vNextMarker = $listResult->getNextMarker();
        } while ($vNextMarker != "");
    }
    catch (Exception $e)
    {
        $code = $e->getCode();
        $error_message = $e->getMessage();
        return "ERROR:$code:$error_message";
    }
    return $listResult;
}

但是,这些共享中的快照的 sintaxis 或方法如何相同?

这不起作用:

function ListSnapshotFolder($shareName, $path, $snapshot)
{
    global $fileRestProxy;
    $vMaxResultados = 5000;
    $vNextMarker = "";
    $listResult = null;
    try
    {
        do
        {
            $options = new ListDirectoriesAndFilesOptions();
            $options->setMaxResults($vMaxResultados);
            $options->setMarker($vNextMarker);
            $shareFull = $shareName . "?snapshot=" . $snapshot; 
            $listResult = $fileRestProxy->ListDirectoriesAndFiles($shareFull,$path,$options);
            $vNextMarker = $listResult->getNextMarker();
        } while ($vNextMarker != "");
    }
    catch (Exception $e)
    {
        $code = $e->getCode();
        $error_message = $e->getMessage();
        return "ERROR:$code:$error_message";
    }
    return $listResult;
}

$option 对象中是否有要添加的参数? 或者也许 $shareFull 必须以某种格式创建? $shareFull = $shareName 。 “?快照=”。 $快照;

提前致谢。

【问题讨论】:

    标签: php azure azure-storage fileshare storage-file-share


    【解决方案1】:

    我相信您在 SDK 中发现了一个错误。我查了源代码here,没有规定在选项中提供sharesnapshot查询字符串参数,代码甚至没有处理它。

        public function listDirectoriesAndFilesAsync(
            $share,
            $path = '',
            ListDirectoriesAndFilesOptions $options = null
        ) {
            Validate::notNull($share, 'share');
            Validate::canCastAsString($share, 'share');
            Validate::canCastAsString($path, 'path');
    
            $method      = Resources::HTTP_GET;
            $headers     = array();
            $postParams  = array();
            $queryParams = array();
            $path        = $this->createPath($share, $path);
    
            if (is_null($options)) {
                $options = new ListDirectoriesAndFilesOptions();
            }
    
            $this->addOptionalQueryParam(
                $queryParams,
                Resources::QP_REST_TYPE,
                'directory'
            );
            $this->addOptionalQueryParam(
                $queryParams,
                Resources::QP_COMP,
                'list'
            );
            $this->addOptionalQueryParam(
                $queryParams,
                Resources::QP_PREFIX_LOWERCASE,
                $options->getPrefix()
            );
            $this->addOptionalQueryParam(
                $queryParams,
                Resources::QP_MARKER_LOWERCASE,
                $options->getNextMarker()
            );
            $this->addOptionalQueryParam(
                $queryParams,
                Resources::QP_MAX_RESULTS_LOWERCASE,
                $options->getMaxResults()
            );
    
            $this->addOptionalQueryParam(
                $queryParams,
                Resources::QP_TIMEOUT,
                $options->getTimeout()
            );
    
            $dataSerializer = $this->dataSerializer;
    
            return $this->sendAsync(
                $method,
                $headers,
                $queryParams,
                $postParams,
                $path,
                Resources::STATUS_OK,
                Resources::EMPTY_STRING,
                $options
            )->then(function ($response) use ($dataSerializer) {
                $parsed = $dataSerializer->unserialize($response->getBody());
                return ListDirectoriesAndFilesResult::create(
                    $parsed,
                    Utilities::getLocationFromHeaders($response->getHeaders())
                );
            }, null);
        }
    

    您可能想在此处提出问题:https://github.com/Azure/azure-storage-php/issues 并将其提交给 SDK 团队。

    【讨论】:

    • 好的,我会打开一个问题。我让这个问题同时开放。谢谢
    猜你喜欢
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2022-07-08
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    相关资源
    最近更新 更多