Exemplo n.º 1
0
        // ReSharper disable once InconsistentNaming
        async Task UploadToAWS(AWSUploadPolicy uploadRequest, FileStream inputStream)
        {
            var s3PostUploadSignedPolicy =
                S3PostUploadSignedPolicy.GetSignedPolicyFromJson(uploadRequest.EncryptedPolicy);

            s3PostUploadSignedPolicy.SecurityToken = uploadRequest.SecurityToken;
            var uploadResponse = await Task.Run(() => AmazonS3Util.PostUpload(new S3PostUploadRequest {
                Key                   = uploadRequest.Key,
                Bucket                = uploadRequest.BucketName,
                CannedACL             = uploadRequest.ACL,
                ContentType           = uploadRequest.ContentType,
                SuccessActionRedirect = uploadRequest.CallbackUrl,
                InputStream           = inputStream,
                SignedPolicy          = s3PostUploadSignedPolicy
            })).ConfigureAwait(false);

            if (uploadResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Amazon upload failed: " + uploadResponse.StatusCode);
            }
        }
Exemplo n.º 2
0
        private S3PostUploadResponse testPost(string key, string bucketName, Stream contentStream, string extraConditions, AWSCredentials credentials, RegionEndpoint region)
        {
            var expDate = DateTime.UtcNow.AddMinutes(5).ToString(AWSSDKUtils.ISO8601DateFormat, CultureInfo.InvariantCulture);

            var policy = policy_tmpl.Replace("EXPIRATIONDATE", expDate)
                         .Replace("BUCKETNAME", bucketName)
                         .Replace("MOARCONDITIONS", extraConditions);

            var signedPolicy = S3PostUploadSignedPolicy.GetSignedPolicy(policy, credentials);

            var req = new S3PostUploadRequest
            {
                Key          = key,
                Bucket       = bucketName,
                CannedACL    = S3CannedACL.PublicRead,
                InputStream  = contentStream,
                SignedPolicy = signedPolicy,
                Region       = region
            };

            return(AmazonS3Util.PostUpload(req));
        }