SetPolicy() public méthode

Set base64 encoded policy to form dictionary.
public SetPolicy ( string policyBase64 ) : void
policyBase64 string
Résultat void
Exemple #1
0
        /// <summary>
        ///  Presigned post policy
        /// </summary>
        public Dictionary <string, string> PresignedPostPolicy(PostPolicy policy)
        {
            if (!policy.IsBucketSet())
            {
                throw new ArgumentException("bucket should be set");
            }

            if (!policy.IsKeySet())
            {
                throw new ArgumentException("key should be set");
            }

            if (!policy.IsExpirationSet())
            {
                throw new ArgumentException("expiration should be set");
            }

            string   region      = Regions.GetRegion(this.client.BaseUrl.Host);
            DateTime signingDate = DateTime.UtcNow;

            policy.SetAlgorithm("AWS4-HMAC-SHA256");
            policy.SetCredential(this.authenticator.GetCredentialString(signingDate, region));
            policy.SetDate(signingDate);

            string policyBase64 = policy.Base64();
            string signature    = this.authenticator.PresignPostSignature(region, signingDate, policyBase64);

            policy.SetPolicy(policyBase64);
            policy.SetSignature(signature);

            return(policy.GetFormData());
        }
Exemple #2
0
        /// <summary>
        ///  Presigned post policy
        /// </summary>
        public async Task <Tuple <string, Dictionary <string, string> > > PresignedPostPolicyAsync(PostPolicy policy)
        {
            string region = null;

            if (!policy.IsBucketSet())
            {
                throw new ArgumentException("bucket should be set");
            }

            if (!policy.IsKeySet())
            {
                throw new ArgumentException("key should be set");
            }

            if (!policy.IsExpirationSet())
            {
                throw new ArgumentException("expiration should be set");
            }

            // Initialize a new client.
            if (!BucketRegionCache.Instance.Exists(policy.Bucket))
            {
                region = await BucketRegionCache.Instance.Update(this, policy.Bucket);
            }
            else
            {
                region = BucketRegionCache.Instance.Region(policy.Bucket);
            }
            // Set Target URL
            Uri requestUrl = RequestUtil.MakeTargetURL(this.BaseUrl, this.Secure, bucketName: policy.Bucket, region: region, usePathStyle: false);

            SetTargetURL(requestUrl);
            DateTime signingDate = DateTime.UtcNow;

            policy.SetAlgorithm("AWS4-HMAC-SHA256");
            policy.SetCredential(this.authenticator.GetCredentialString(signingDate, region));
            policy.SetDate(signingDate);

            string policyBase64 = policy.Base64();
            string signature    = this.authenticator.PresignPostSignature(region, signingDate, policyBase64);

            policy.SetPolicy(policyBase64);
            policy.SetSignature(signature);

            return(new Tuple <string, Dictionary <string, string> >(this.restClient.BaseUrl.AbsoluteUri, policy.GetFormData()));
        }
        /// <summary>
        ///  Presigned post policy
        /// </summary>
        public Dictionary<string, string> PresignedPostPolicy(PostPolicy policy)
        {
            if (!policy.IsBucketSet())
                {
                        throw new ArgumentException("bucket should be set");
                }

                if (!policy.IsKeySet())
                {
                        throw new ArgumentException("key should be set");
                }

                if (!policy.IsExpirationSet())
                {
                        throw new ArgumentException("expiration should be set");
                }

                string region = Regions.GetRegion(this.client.BaseUrl.Host);
                DateTime signingDate = DateTime.UtcNow;

                policy.SetAlgorithm("AWS4-HMAC-SHA256");
                policy.SetCredential(this.authenticator.GetCredentialString(signingDate, region));
                policy.SetDate(signingDate);

                string policyBase64 = policy.Base64();
                string signature = this.authenticator.PresignPostSignature(signingDate, region, policyBase64);

                policy.SetPolicy(policyBase64);
                policy.SetSignature(signature);

                return policy.getFormData();
        }