Example #1
0
        public async Task <JsonResult> Get()
        {
            var keys = await S3Client.GetAllObjectKeysAsync(BucketName, UserId, new Dictionary <string, object> {
            });

            try
            {
                var tasks = new List <Task <GetObjectResponse> >();
                foreach (var key in keys)
                {
                    tasks.Add(S3Client.GetObjectAsync(new GetObjectRequest
                    {
                        BucketName = BucketName,
                        Key        = key
                    }));
                }
                Task.WaitAll(tasks.ToArray());
                var models = new List <MessageModel> {
                };
                foreach (var task in tasks)
                {
                    StreamReader reader  = new StreamReader(task.Result.ResponseStream);
                    string       rawJson = reader.ReadToEnd();
                    var          model   = JsonSerializer.Deserialize <MessageModel>(rawJson);
                    var          k       = task.Result.Key.Split('/');
                    model.Key = k[k.Length - 1];
                    models.Add(model);
                }
                Response.ContentType = "text/json";
                return(new JsonResult(models));
            }
            catch (AmazonS3Exception e)
            {
                Response.StatusCode = (int)e.StatusCode;
                return(new JsonResult(e.Message));
            }
        }