コード例 #1
0
        public string DistributeFile(string sourcePath)
        {
            using (Stream fileStream = File.OpenRead(sourcePath))
            {
                Console.Write($"Distributing {Path.GetFileName(sourcePath)}");

                PutObjectRequest request = new PutObjectRequest()
                {
                    BucketName      = _bucketPath,
                    Key             = System.IO.Path.GetFileName(sourcePath),
                    CannedACL       = S3CannedACL.PublicRead,
                    InputStream     = fileStream,
                    AutoCloseStream = true,
                };
                request.StreamTransferProgress += (sender, e) =>
                {
                    Amazon.Runtime.StreamTransferProgressArgs args = (e as Amazon.Runtime.StreamTransferProgressArgs);
                    args.PercentDone.WriteProgressToConsole();
                };
                PutObjectResponse response = _client.PutObject(request);
                Console.WriteLine();

                return(_client.GeneratePreSignedURL(_bucketPath, Path.GetFileName(sourcePath), DateTime.UtcNow.AddYears(10), null));
            }
        }
コード例 #2
0
 public string GetUrl(string path)
 {
     try
     {
         return(client.GeneratePreSignedURL(Bucket, path, DateTime.UtcNow.AddDays(1), new Dictionary <string, object>()));
     }
     catch (Exception ex)
     {
         Console.WriteLine($"GetUrl:s3:{ex.Message}{ex.InnerException}");
         return("");
     }
 }
コード例 #3
0
        public void ProcessBucket(string bucket, SkRecognitionClient recognitionClient)
        {
            ListObjectsV2Request req = new ListObjectsV2Request
            {
                BucketName = bucket,
            };



            try
            {
                ListObjectsV2Response response = null;
                do
                {
                    response = yandexS3.ListObjectsV2Async(req).GetAwaiter().GetResult();

                    if (response.HttpStatusCode != HttpStatusCode.OK)
                    {
                        log.LogError($"HttpRequest error {response.HttpStatusCode}");
                    }

                    var qResponse = response.S3Objects.AsQueryable <S3Object>();
                    var retVal    = from key in qResponse
                                    where key.Key.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase) || key.Key.EndsWith(".ogg", StringComparison.InvariantCultureIgnoreCase)
                                    orderby key.Key
                                    select new SkTaskModel
                    {
                        AudioUrl = yandexS3.GeneratePreSignedURL(bucket, key.Key, DateTime.Now.AddHours(24), null),
                        Path     = key.Key,
                        TaskId   = null
                    };

                    // Set the marker property
                    req.ContinuationToken = response.NextContinuationToken;

                    recognitionClient.CreateRecognitionTask(retVal.ToArray <SkTaskModel>());
                } while (response != null && response.IsTruncated);
            }
            catch (Exception ex)
            {
                log.LogError(ex, "GetObjectList execution error");
            };
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: NingMoe/HelloWorld
        public static void Main(string[] args)
        {
            if (checkRequiredFields())
            {
                using (client = new AmazonS3Client("AKIAPP3Y4VFTXZK66NZA", "yvwt1aVEipUt41qiNROw6GNnxU+6CAU0xNE3MNZl", RegionEndpoint.CNNorth1))
                {
                    Console.WriteLine("Listing buckets");
                    //  ListingBuckets();

                    Console.WriteLine("Creating a bucket");
                    //CreateABucket();

                    Console.WriteLine("Writing an object");
                    WritingAnObject();

                    Console.WriteLine("Reading an object");
                    ReadingAnObject();

                    //Console.WriteLine("Deleting an object");
                    //DeletingAnObject();

                    Console.WriteLine("Listing objects");
                    ListingObjects();

                    String url = client.GeneratePreSignedURL(bucketName, keyName, DateTime.Now.AddDays(1), null);

                    String url1 = SignURL(bucketName, keyName, null, TimeSpan.FromDays(1));


                    Console.WriteLine(url);
                    Console.WriteLine(url1);
                }
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }
コード例 #5
0
        public static string GetPresignedURL(IAmazonS3 s3Client, string bucketName, string key)
        {
            string signedUrl = s3Client.GeneratePreSignedURL(bucketName, key, DateTime.Now.AddMinutes(20), null);

            return(signedUrl);
        }
コード例 #6
0
ファイル: S3.cs プロジェクト: TcmExtensions/S3ECLProvider
 /// <summary>
 /// Gets the full media URL of the specified AWS S3 asset
 /// </summary>
 /// <param name="key">AWS S3 ECL Key.</param>
 /// <returns>Absolute URL to the asset</returns>
 internal String GetMediaUrl(String key)
 {
     return(_S3Client.GeneratePreSignedURL(_bucketName, _prefix + VirtualPathUtility.RemoveTrailingSlash(key), DateTime.Now.AddDays(1), null));
 }