示例#1
0
        public async Task <int> UploadLargeFilesToCloud()
        {
            #region "for large file upload; but the below code doesn't work porperly as it cann't append data at tardigrade server side;"
            var restrictedBucketService = new BucketService(access);

            var newBucketName = "flureebucket";
            var file          = await GetFlureeSnapshot("file.mp4");

            var bucket = await restrictedBucketService.GetBucketAsync(newBucketName);

            using Stream source = File.OpenRead(file.FileName);
            int    chunkSize  = 4 * 1024 * 1024;
            long   uploadSize = chunkSize;
            byte[] buffer     = new byte[chunkSize];
            int    bytesRead;
            while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
            {
                var uploadOperationRestricted = await objectService.UploadObjectAsync(bucket, file.FileName, new UploadOptions(), buffer, true);

                uploadOperationRestricted.UploadOperationProgressChanged += UploadOperationRestricted_UploadOperationProgressChanged;
                uploadOperationRestricted.UploadOperationEnded           += UploadOperationRestricted_UploadOperationEnded;
                await uploadOperationRestricted.StartUploadAsync();

                var mb = ((float)uploadSize / (float)file.File.Length) * 100;
                Console.WriteLine($"{mb} % uploaded");
                uploadSize += chunkSize;
            }

            return(0);

            #endregion
        }
示例#2
0
        public async Task RevokeAccess_MakesAccesUnusable()
        {
            string serializedAccess;
            string bucketname = "revoke-access-makes-access-unusable";

            byte[] bytesToUpload = ObjectServiceTest.GetRandomBytes(2048);

            using (Access scope = new Access(TestConstants.SATELLITE_URL, TestConstants.VALID_API_KEY, TestConstants.ENCRYPTION_SECRET))
            {
                await _bucketService.CreateBucketAsync(bucketname);

                Permission permission = new Permission();
                permission.AllowUpload = true;
                List <SharePrefix> sharePrefixes = new List <SharePrefix>();
                sharePrefixes.Add(new SharePrefix()
                {
                    Bucket = bucketname, Prefix = "test/"
                });
                var restricted = scope.Share(permission, sharePrefixes);
                serializedAccess = restricted.Serialize();

                await Task.Delay(SATELLITE_WAIT_DURATION); //Wait a bit so that some things can happen on the satellite

                Access restrictedEnv;
                try
                {
                    restrictedEnv = new Access(serializedAccess);
                }
                catch
                {
                    Assert.Fail("Failed to create restricted scope from serialized scope");
                    return;
                }

                var restrictedObjectService = new ObjectService(restrictedEnv);
                var restrictedBucketService = new BucketService(restrictedEnv);
                var restrictedBucket        = await restrictedBucketService.GetBucketAsync(bucketname);

                var uploadOperationRestricted = await restrictedObjectService.UploadObjectAsync(restrictedBucket, "test/subfolder/test-file-upload", new UploadOptions(), bytesToUpload, false);

                await uploadOperationRestricted.StartUploadAsync();

                Assert.IsTrue(uploadOperationRestricted.Completed);
                Assert.AreEqual(bytesToUpload.Length, uploadOperationRestricted.BytesSent);

                //Revoke access
                await scope.RevokeAsync(restrictedEnv);

                //Try uploading again
                var uploadOperationRestricted2 = await restrictedObjectService.UploadObjectAsync(restrictedBucket, "test/subfolder/test-file-upload", new UploadOptions(), bytesToUpload, false);

                await uploadOperationRestricted2.StartUploadAsync();

                Assert.IsFalse(uploadOperationRestricted2.Completed);
                Assert.IsTrue(uploadOperationRestricted2.Failed);
            }
        }
示例#3
0
        public async Task AccessShare_Creates_UsableSharedAccessForUploadDeep()
        {
            string serializedAccess;
            string bucketname = "accessshare-creates-usablesharedaccessforuploaddeep";

            byte[] bytesToUpload = ObjectServiceTest.GetRandomBytes(2048);

            using (Access scope = new Access(TestConstants.SATELLITE_URL, TestConstants.VALID_API_KEY, TestConstants.ENCRYPTION_SECRET))
            {
                await _bucketService.CreateBucketAsync(bucketname);

                Permission permission = new Permission();
                permission.AllowUpload   = true;
                permission.AllowDownload = false; //should not change anything as we are uploading here
                List <SharePrefix> sharePrefixes = new List <SharePrefix>();
                sharePrefixes.Add(new SharePrefix()
                {
                    Bucket = bucketname, Prefix = "test/subfolder/"
                });
                var restricted = scope.Share(permission, sharePrefixes);
                serializedAccess = restricted.Serialize();
            }

            await Task.Delay(SATELLITE_WAIT_DURATION); //Wait a bit so that some things can happen on the satellite

            Access restrictedEnv;

            try
            {
                restrictedEnv = new Access(serializedAccess);
            }
            catch
            {
                Assert.Fail("Failed to create restricted scope from serialized scope");
                return;
            }

            var restrictedObjectService = new ObjectService(restrictedEnv);
            var restrictedBucketService = new BucketService(restrictedEnv);
            var restrictedBucket        = await restrictedBucketService.GetBucketAsync(bucketname);

            var uploadOperationRestricted = await restrictedObjectService.UploadObjectAsync(restrictedBucket, "test/subfolder/test-file-upload", new UploadOptions(), bytesToUpload, false);

            await uploadOperationRestricted.StartUploadAsync();

            Assert.IsTrue(uploadOperationRestricted.Completed);
            Assert.AreEqual(bytesToUpload.Length, uploadOperationRestricted.BytesSent);
        }