Ejemplo n.º 1
0
        public async Task <dynamic> DeleteBucket([FromBody] CreateBucketModel bucket)
        {
            BucketsApi buckets = new BucketsApi();
            dynamic    token   = await OAuthController.GetInternalAsync();

            buckets.Configuration.AccessToken = token.access_token;

            await buckets.DeleteBucketAsync(bucket.bucketKey);

            //or
            //buckets.DeleteBucket(bucket.bucketKey);

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public async Task <dynamic> UploadObject()
        {
            // basic input validation
            HttpRequest req = HttpContext.Current.Request;

            if (string.IsNullOrWhiteSpace(req.Params["bucketKey"]))
            {
                throw new System.Exception("BucketKey parameter was not provided.");
            }

            if (req.Files.Count != 1)
            {
                throw new System.Exception("Missing file to upload"); // for now, let's support just 1 file at a time
            }
            string         bucketKey = req.Params["bucketKey"];
            HttpPostedFile file      = req.Files[0];

            // save the file on the server
            var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), file.FileName);

            file.SaveAs(fileSavePath);

            // get the bucket...
            dynamic oauth = await OAuthController.GetInternalAsync();

            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = oauth.access_token;

            // upload the file/object, which will create a new object
            dynamic uploadedObj;

            using (StreamReader streamReader = new StreamReader(fileSavePath))
            {
                uploadedObj = await objects.UploadObjectAsync(bucketKey,
                                                              file.FileName, (int)streamReader.BaseStream.Length, streamReader.BaseStream,
                                                              "application/octet-stream");
            }

            // cleanup
            File.Delete(fileSavePath);

            return(uploadedObj);
        }