1

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
brian enno
  • 400
  • 5
  • 16

1 Answers1

1

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.

nealibob
  • 119
  • 8