微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 php 从文件共享快照中列出 Azure 文件和文件夹

如何解决使用 php 从文件共享快照中列出 Azure 文件和文件夹

要列出 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;
}

但是如何与这些共享中的快照相同的语法或方法

这不起作用:

function ListSnapshotFolder($shareName,$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,$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 。 “?快照=”。 $快照;

提前致谢。

解决方法

我相信您在 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 团队注意。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?