使用S3 .NET客户端中的条件开始

发布于 2025-02-01 04:31:57 字数 952 浏览 4 评论 0原文

我正在与S3 .NET客户端合作,并且我能够得到一个预先签名的URL(我遵循本教程在线)。我想让用户仅将其文件存储在特定路径中(例如,进入'testTest/'文件夹)。

另一个堆栈Frows 使用:

Conditions=[["starts-with", "$key", "uploads/"]]

我正在使用.NET S3客户端,实际上似乎无法设置此条件。 您有一个想法如何设置“开始”选项?

我尝试使用以下几行中显示的“参数”而没有成功。

        < !--language - all: cs-- >
        GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
        {
            BucketName = _BucketName,
            Key = key,
            Expires = expiryTime,
            Verb = HttpVerb.PUT
        };
        request1.Parameters.Add("Conditions", "[\"starts-with\", \"testtest/\"]"); // <== THIS LINE

I'm working with the S3 .net client and I'm perfectly able to get a presigned url (I followed this tutorial online). I would like to let the user to store their files in a specific path only (for example into the 'testtest/' folder).

As explained also here in another StackFlow thread, is possible to use:

Conditions=[["starts-with", "$key", "uploads/"]]

I'm using the .net S3 client and actually seems that there is no way to set this condition.
Do you have an idea how to set "starts-with" option?

I tried to use the "parameters" as show in the following lines without success.

        < !--language - all: cs-- >
        GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
        {
            BucketName = _BucketName,
            Key = key,
            Expires = expiryTime,
            Verb = HttpVerb.PUT
        };
        request1.Parameters.Add("Conditions", "[\"starts-with\", \"testtest/\"]"); // <== THIS LINE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是我的挚爱i 2025-02-08 04:31:58

看来您有正确的想法,但是您的病情无效。条件实际上是一系列条件,启动与需要知道要看什么,因此类似的事情应该有效:

Parameters = { ["Conditions"] = "[[\"starts-with\", \"$key\", \"testtest/\"]]" }

这是否实际上有帮助。似乎最好的做法是在上传之前,在每个文件(键)上获取一个签名的URL。

It looks like you had the right idea, but your condition was not valid. Conditions is actually an array of conditions, and starts-with needs to know what to look at, so something like this should work:

Parameters = { ["Conditions"] = "[[\"starts-with\", \"$key\", \"testtest/\"]]" }

Whether or not this actually helps is somewhat debatable. It seems the best practice is to get a signed URL for each file (key) before uploading against it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文