public async Task <Movie> UploadMovie(String bucketName, String Title, System.IO.Stream VideoPath, System.IO.Stream CoverPath) { DynamoDBContext Context = new DynamoDBContext(dynamoDBClient); Movie movie = new Movie(); movie.Id = System.Guid.NewGuid().ToString(); movie.Title = Title; movie.Cover = S3Link.Create(Context, bucketName, movie.Id + "1.jpg", Region); movie.Video = S3Link.Create(Context, bucketName, movie.Id + "2.avi", Region); var fileTransferUtility = new TransferUtility(s3Client); var cover = new TransferUtilityUploadRequest() { CannedACL = S3CannedACL.PublicRead, BucketName = bucketName, Key = movie.Id + "1.jpg", InputStream = CoverPath }; var video = new TransferUtilityUploadRequest() { CannedACL = S3CannedACL.PublicRead, BucketName = bucketName, Key = movie.Id + "2.avi", InputStream = VideoPath }; await fileTransferUtility.UploadAsync(cover); await fileTransferUtility.UploadAsync(video); await Context.SaveAsync <Movie>(movie); return(await GetMovie(movie.Id)); }
public async Task <Movie> UploadFile(string BucketName, string MovieTitle, Stream MovieVideoPath, Stream MovieImagePath) { DynamoDBContext Context = new DynamoDBContext(_dynamoDBClient); Movie movie = new Movie(); movie.MovieId = Guid.NewGuid().ToString(); movie.MovieTitle = MovieTitle; movie.MovieImage = S3Link.Create(Context, BucketName, movie.MovieId + "1.jpg", Region); movie.MovieVideo = S3Link.Create(Context, BucketName, movie.MovieId + "2.avi", Region); var fileTransferUtility = new TransferUtility(_s3Client); var MovieImage = new TransferUtilityUploadRequest() { CannedACL = S3CannedACL.PublicRead, BucketName = BucketName, Key = movie.MovieId + "1.jpg", InputStream = MovieImagePath }; var MovieVideo = new TransferUtilityUploadRequest() { CannedACL = S3CannedACL.PublicRead, BucketName = BucketName, Key = movie.MovieId + "2.avi", InputStream = MovieVideoPath }; await fileTransferUtility.UploadAsync(MovieImage); await fileTransferUtility.UploadAsync(MovieVideo); await Context.SaveAsync <Movie>(movie); return(await GetMovie(movie.MovieId)); }
public async Task <Movie> UploadMovie(String bucketName, String Title, String VideoPath, String CoverPath) { DynamoDBContext Context = new DynamoDBContext(dynamoDBClient); Movie movie = new Movie(); movie.Id = System.Guid.NewGuid().ToString(); movie.Title = Title; movie.Cover = S3Link.Create(Context, bucketName, movie.Id + "1", Region); movie.Video = S3Link.Create(Context, bucketName, movie.Id + "2", Region); Task task1 = s3Client.UploadObjectFromFilePathAsync( bucketName, movie.Id + "1", CoverPath, new Dictionary <string, object>(), default(System.Threading.CancellationToken)); Task task2 = s3Client.UploadObjectFromFilePathAsync( bucketName, movie.Id + "2", VideoPath, new Dictionary <string, object>(), default(System.Threading.CancellationToken)); //movie.Cover.UploadFrom(CoverPath); //movie.Video.UploadFrom(VideoPath); await Context.SaveAsync <Movie>(movie); return(await GetMovie(movie.Id, false)); }
private void uploadBtn_Click(object sender, RoutedEventArgs e) { isbn = isbnTxt.Text; title = titleTxt.Text; author = authorTxt.Text; string fileTitle = System.IO.Path.GetFileName(pdfPath); Book newBook = new Book { ISBN = isbn, Title = title, Author = author, CurrentPage = 1, PDFFile = S3Link.Create(context, bucketName, fileTitle, Amazon.RegionEndpoint.USWest2) }; context.Save <Book>(newBook); newBook.PDFFile.UploadFrom(pdfPath); loadBookRepo(); }
private void TestHashObjects() { string bucketName = "aws-sdk-net-s3link-" + DateTime.Now.Ticks; var s3Client = new Amazon.S3.AmazonS3Client(Amazon.RegionEndpoint.USEast1); s3Client.PutBucket(bucketName); try { // Create and save item Product product = new Product { Id = 1, Name = "CloudSpotter", CompanyName = "CloudsAreGrate", Price = 1200, TagSet = new HashSet <string> { "Prod", "1.0" }, CurrentStatus = Status.Active, FormerStatus = Status.Upcoming, Supports = Support.Windows | Support.Abacus, PreviousSupport = null, InternalId = "T1000", IsPublic = true, AlwaysN = true, Rating = 4, Components = new List <string> { "Code", "Coffee" }, KeySizes = new List <byte> { 16, 64, 128 }, CompanyInfo = new CompanyInfo { Name = "MyCloud", Founded = new DateTime(1994, 7, 6), Revenue = 9001, AllProducts = new List <Product> { new Product { Id = 12, Name = "CloudDebugger" }, new Product { Id = 13, Name = "CloudDebuggerTester" } }, CompetitorProducts = new Dictionary <string, List <Product> > { { "CloudsAreOK", new List <Product> { new Product { Id = 90, Name = "CloudSpotter RipOff" }, new Product { Id = 100, Name = "CloudDebugger RipOff" }, } }, { "CloudsAreBetter", new List <Product> { new Product { Id = 92, Name = "CloudSpotter RipOff 2" }, new Product { Id = 102, Name = "CloudDebugger RipOff 3" }, } }, } }, Map = new Dictionary <string, string> { { "a", "1" }, { "b", "2" } } }; product.FullProductDescription = S3Link.Create(Context, bucketName, "my-product", Amazon.RegionEndpoint.USEast1); product.FullProductDescription.UploadStream(new MemoryStream(UTF8Encoding.UTF8.GetBytes("Lots of data"))); Context.Save(product); // Test conversion var doc = Context.ToDocument(product); Assert.IsNotNull(doc["Tags"].AsPrimitiveList()); //if (DynamoDBEntryConversion.Schema == DynamoDBEntryConversion.ConversionSchema.V1) // Assert.IsNotNull(doc["Components"].AsPrimitiveList()); //else // Assert.IsNotNull(doc["Components"].AsDynamoDBList()); Assert.IsTrue( doc["Components"].AsPrimitiveList() != null || doc["Components"].AsDynamoDBList() != null); Assert.IsNotNull(doc["CompanyInfo"].AsDocument()); Assert.IsNotNull(doc["Supports"]); // Load item Product retrieved = Context.Load <Product>(1); Assert.AreEqual(product.Id, retrieved.Id); Assert.AreEqual(product.TagSet.Count, retrieved.TagSet.Count); Assert.AreEqual(product.Components.Count, retrieved.Components.Count); Assert.IsNull(retrieved.InternalId); Assert.AreEqual(product.CurrentStatus, retrieved.CurrentStatus); Assert.AreEqual(product.FormerStatus, retrieved.FormerStatus); Assert.AreEqual(product.Supports, retrieved.Supports); Assert.AreEqual(product.PreviousSupport, retrieved.PreviousSupport); Assert.AreEqual(product.IsPublic, retrieved.IsPublic); Assert.AreEqual(product.Rating, retrieved.Rating); Assert.AreEqual(product.KeySizes.Count, retrieved.KeySizes.Count); Assert.IsNotNull(retrieved.CompanyInfo); Assert.AreEqual(product.CompanyInfo.Name, retrieved.CompanyInfo.Name); Assert.AreEqual(product.CompanyInfo.Founded, retrieved.CompanyInfo.Founded); Assert.AreNotEqual(product.CompanyInfo.Revenue, retrieved.CompanyInfo.Revenue); Assert.AreEqual(product.CompanyInfo.AllProducts.Count, retrieved.CompanyInfo.AllProducts.Count); Assert.AreEqual(product.CompanyInfo.AllProducts[0].Id, retrieved.CompanyInfo.AllProducts[0].Id); Assert.AreEqual(product.CompanyInfo.AllProducts[1].Id, retrieved.CompanyInfo.AllProducts[1].Id); Assert.AreEqual(product.Map.Count, retrieved.Map.Count); Assert.AreEqual(product.CompanyInfo.CompetitorProducts.Count, retrieved.CompanyInfo.CompetitorProducts.Count); Assert.AreEqual(product.CompanyInfo.CompetitorProducts.ElementAt(0).Key, retrieved.CompanyInfo.CompetitorProducts.ElementAt(0).Key); Assert.AreEqual(product.CompanyInfo.CompetitorProducts.ElementAt(0).Value.Count, retrieved.CompanyInfo.CompetitorProducts.ElementAt(0).Value.Count); Assert.AreEqual(product.CompanyInfo.CompetitorProducts.ElementAt(1).Key, retrieved.CompanyInfo.CompetitorProducts.ElementAt(1).Key); Assert.AreEqual(product.CompanyInfo.CompetitorProducts.ElementAt(1).Value.Count, retrieved.CompanyInfo.CompetitorProducts.ElementAt(1).Value.Count); Assert.IsNotNull(retrieved.FullProductDescription); using (var stream = retrieved.FullProductDescription.OpenStream()) using (var reader = new StreamReader(stream)) { Assert.AreEqual("Lots of data", reader.ReadToEnd()); } // Try saving circularly-referencing object product.CompanyInfo.AllProducts.Add(product); AssertExtensions.ExpectException(() => Context.Save(product)); product.CompanyInfo.AllProducts.RemoveAt(2); // Create and save new item product.Id++; product.Price = 94; product.TagSet = null; product.Components = null; product.CurrentStatus = Status.Upcoming; product.IsPublic = false; product.AlwaysN = false; product.Rating = null; product.KeySizes = null; Context.Save(product); // Load new item retrieved = Context.Load <Product>(product); Assert.AreEqual(product.Id, retrieved.Id); Assert.IsNull(retrieved.TagSet); Assert.IsNull(retrieved.Components); Assert.IsNull(retrieved.InternalId); Assert.AreEqual(product.CurrentStatus, retrieved.CurrentStatus); Assert.AreEqual(product.IsPublic, retrieved.IsPublic); Assert.AreEqual(product.AlwaysN, retrieved.AlwaysN); Assert.AreEqual(product.Rating, retrieved.Rating); Assert.IsNull(retrieved.KeySizes); // Enumerate all products and save their Ids List <int> productIds = new List <int>(); IEnumerable <Product> products = Context.Scan <Product>(); foreach (var p in products) { productIds.Add(p.Id); } Assert.AreEqual(2, productIds.Count); // Load first product var firstId = productIds[0]; product = Context.Load <Product>(firstId); Assert.IsNotNull(product); Assert.AreEqual(firstId, product.Id); // Query GlobalIndex products = Context.Query <Product>( product.CompanyName, // Hash-key for the index is Company QueryOperator.GreaterThan, // Range-key for the index is Price, so the new object[] { 90 }, // condition is against a numerical value new DynamoDBOperationConfig // Configure the index to use { IndexName = "GlobalIndex", }); Assert.AreEqual(2, products.Count()); // Query GlobalIndex with an additional non-key condition products = Context.Query <Product>( product.CompanyName, // Hash-key for the index is Company QueryOperator.GreaterThan, // Range-key for the index is Price, so the new object[] { 90 }, // condition is against a numerical value new DynamoDBOperationConfig // Configure the index to use { IndexName = "GlobalIndex", QueryFilter = new List <ScanCondition> { new ScanCondition("TagSet", ScanOperator.Contains, "1.0") } }); Assert.AreEqual(1, products.Count()); // Delete first product Context.Delete <Product>(firstId); product = Context.Load <Product>(product.Id); Assert.IsNull(product); // Scan the table products = Context.Scan <Product>(); Assert.AreEqual(1, products.Count()); // Scan the table with consistent read products = Context.Scan <Product>( new ScanCondition[] { }, new DynamoDBOperationConfig { ConsistentRead = true }); Assert.AreEqual(1, products.Count()); // Test a versioned product VersionedProduct vp = new VersionedProduct { Id = 3, Name = "CloudDebugger", CompanyName = "CloudsAreGrate", Price = 9000, TagSet = new HashSet <string> { "Test" }, }; Context.Save(vp); // Update and save vp.Price++; Context.Save(vp); // Alter the version and try to save vp.Version = 0; AssertExtensions.ExpectException(() => Context.Save(vp)); // Load and save vp = Context.Load(vp); Context.Save(vp); } finally { Amazon.S3.Util.AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName); } }