コード例 #1
0
        public async void RetrieveListOfObjects()
        {
            AmazonS3Client     client      = AmazonServices.Instance(Assets).Client;
            ListObjectsRequest listRequest = new ListObjectsRequest()
            {
                BucketName = AmazonServices.BucketName
            };

            try
            {
                ListObjectsResponse listResponse = await client.ListObjectsAsync(listRequest);

                var objects = listResponse.S3Objects.Select(o =>
                {
                    string file;
                    using (var response = client.GetObjectAsync(AmazonServices.BucketName, o.Key).Result)
                        using (var reader = new StreamReader(response.ResponseStream))
                        {
                            file = reader.ReadToEnd();
                        }

                    SpritistData data = JsonConvert.DeserializeObject <SpritistData>(file);
                    return(data);
                });
                listView.Adapter = new SpritistListAdapter(this, objects);
            }
            catch (Exception e)
            {
                Toast.MakeText(this, "Could not load images", ToastLength.Long);
            }
        }
コード例 #2
0
        private async void UploadImage()
        {
            // aws upload
            var services = AmazonServices.Instance(Assets);
            var client   = services.Client;

            // pack things into a stream
            SpritistData data = new SpritistData(spriteName, sourceBitmap);

            string json = JsonConvert.SerializeObject(data, Formatting.Indented);

            PutObjectRequest request = new PutObjectRequest()
            {
                BucketName  = AmazonServices.BucketName,
                Key         = spriteName + "-" + GenerateKey(10),
                ContentBody = json
            };

            request.ContentType = AmazonServicesContentType.Json;

            await client.PutObjectAsync(request);

            Toast.MakeText(this, "Uploaded Image.", ToastLength.Long);

            //using (MemoryStream ms = new MemoryStream())
            //using (StreamWriter streamWriter = new StreamWriter(ms))
            //using (JsonWriter jsonWriter = new JsonTextWriter(streamWriter))
            //{
            //    serializer.Serialize(jsonWriter, data);

            //    PutObjectRequest request = new PutObjectRequest()
            //    {
            //        BucketName  = AmazonServices.BucketName,
            //        ContentType = AmazonServicesContentType.Json,
            //        Key = spriteName,
            //        Content = ms
            //    };

            //    PutObjectResponse response = client.PutObjectAsync(request).Result;
            //    Log.Info("Spritist.MakeSpriteActivity", "Put data");
            //}
        }