public async Task <IActionResult> UploadFileNow(ICollection <IFormFile> files) { // get your storage accounts connection string var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=kevinlcst8359lab5;AccountKey=afeNQeUy/qzlOdTnKvVYbBYM0MsDjTgB0ipBl5aMUy/o6PZ+jpxEh2gDtB2nCk06AGj06jdMwPhREmVr1FP0MA==;EndpointSuffix=core.windows.net"); // create an instance of the blob client var blobClient = storageAccount.CreateCloudBlobClient(); // create a container to hold your blob (binary large object.. or something like that) // naming conventions for the curious https://msdn.microsoft.com/en-us/library/dd135715.aspx var container = blobClient.GetContainerReference("kevinsphotostorage"); await container.CreateIfNotExistsAsync(); // set the permissions of the container to 'blob' to make them public var permissions = new BlobContainerPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Blob; await container.SetPermissionsAsync(permissions); // for each file that may have been sent to the server from the client foreach (var file in files) { try { // create the blob to hold the data var blockBlob = container.GetBlockBlobReference(file.FileName); if (await blockBlob.ExistsAsync()) { await blockBlob.DeleteAsync(); } using (var memoryStream = new MemoryStream()) { // copy the file data into memory await file.CopyToAsync(memoryStream); // navigate back to the beginning of the memory stream memoryStream.Position = 0; // send the file to the cloud await blockBlob.UploadFromStreamAsync(memoryStream); } // add the photo to the database if it uploaded successfully var photo = new Photo(); photo.Url = blockBlob.Uri.AbsoluteUri; photo.FileName = file.FileName; _context.Photo.Add(photo); _context.SaveChanges(); } catch { } } return(RedirectToAction("Index")); }
public IActionResult Delete(Photo photo) { var deleteId = (from c in _context.Photos where c.PhotoId == c.PhotoId select c).FirstOrDefault(); //TODO DELETE THE RIGHT ONE NOT THE FIRST ONE EVERY TIME _context.Remove(deleteId); //delete the id object _context.SaveChanges(); //save the changes return(RedirectToAction("Index")); }
public async Task <IActionResult> UploadFile(ICollection <IFormFile> files) { // get your storage accounts connection string var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=boby0003lab5;AccountKey=WjpIn8Zctea9tolVBrJehJBEnxrcaqYycGRePMTGtyaJZ8afhwYPbJfM65jI14AdQNYJoIPgdxJbeWt7ZGFBdw==;EndpointSuffix=core.windows.net"); // create an instance of the blob client var blobClient = storageAccount.CreateCloudBlobClient(); // create a container to hold your blob (binary large object.. or something like that) var container = blobClient.GetContainerReference("patricksphotostorage"); await container.CreateIfNotExistsAsync(); // set the permissions of the container to 'blob' to make them public var permissions = new BlobContainerPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Blob; await container.SetPermissionsAsync(permissions); // for each file that may have been sent to the server from the client foreach (var file in files) { try { // create the blob to hold the data var blockBlob = container.GetBlockBlobReference(file.FileName); if (await blockBlob.ExistsAsync()) { await blockBlob.DeleteAsync(); } using (var memoryStream = new MemoryStream()) { // copy the file data into memory await file.CopyToAsync(memoryStream); // navigate back to the beginning of the memory stream memoryStream.Position = 0; // send the file to the cloud await blockBlob.UploadFromStreamAsync(memoryStream); } // add the photo to the database if it uploaded successfully var photo = new Photo(); photo.Url = blockBlob.Uri.AbsoluteUri; photo.FileName = file.FileName; _PhotoContext.Photos.Add(photo); _PhotoContext.SaveChanges(); } catch { } } return(RedirectToAction("Index")); }
public async Task <IActionResult> UploadFileNow(ICollection <IFormFile> files) { var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=cst8359;AccountKey=ecMPpNU6vimZKMDTJG4seALrY7Kq7UJYjgl0/yLanXn857C8xtUJ2sF4ciB6wy9gg+e/YeYbRTaly2DVOxWhXQ=="); var blobClient = storageAccount.CreateCloudBlobClient(); var container = blobClient.GetContainerReference("aminmahmoudian"); await container.CreateIfNotExistsAsync(); var permissions = new BlobContainerPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Blob; await container.SetPermissionsAsync(permissions); foreach (var file in files) { try { var blockBlob = container.GetBlockBlobReference(file.FileName); if (await blockBlob.ExistsAsync()) { await blockBlob.DeleteAsync(); } using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream); memoryStream.Position = 0; await blockBlob.UploadFromStreamAsync(memoryStream); } var photo = new Photo(); photo.Url = blockBlob.Uri.AbsoluteUri; photo.FileName = file.FileName; _context.Photos.Add(photo); _context.SaveChanges(); } catch { } } return(RedirectToAction("Index")); }
public async Task <IActionResult> UploadFileNow(ICollection <IFormFile> files) { // get your storage accounts connection string var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=cst8359;AccountKey=ecMPpNU6vimZKMDTJG4seALrY7Kq7UJYjgl0/yLanXn857C8xtUJ2sF4ciB6wy9gg+e/YeYbRTaly2DVOxWhXQ=="); // create an instance of the blob client var blobClient = storageAccount.CreateCloudBlobClient(); // create a container to hold your blob (binary large object.. or something like that) // naming conventions for the curious https://msdn.microsoft.com/en-us/library/dd135715.aspx var container = blobClient.GetContainerReference("justinsphotostorage"); await container.CreateIfNotExistsAsync(); // set the permissions of the container to 'blob' to make them public var permissions = new BlobContainerPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Blob; await container.SetPermissionsAsync(permissions); // for each file that may have been sent to the server from the client foreach (var file in files) { try { // create the blob to hold the data var blockBlob = container.GetBlockBlobReference(file.FileName); if (await blockBlob.ExistsAsync()) { await blockBlob.DeleteAsync(); } using (var memoryStream = new MemoryStream()) { // copy the file data into memory await file.CopyToAsync(memoryStream); // navigate back to the beginning of the memory stream memoryStream.Position = 0; // send the file to the cloud await blockBlob.UploadFromStreamAsync(memoryStream); } // add the photo to the database if it uploaded successfully var photo = new Photo(); photo.Url = blockBlob.Uri.AbsoluteUri; photo.FileName = file.FileName; _context.Photos.Add(photo); _context.SaveChanges(); } catch { } } return(RedirectToAction("Index")); }