public IActionResult CreateBlob() { // Create a file in your local MyDocuments folder to upload to a blob. string localPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string localFileName = "naveed-blob-poc_" + Guid.NewGuid().ToString() + ".txt"; string sourceFile = Path.Combine(localPath, localFileName); // Write text to the file. var writer = new System.IO.StreamWriter(localFileName); writer.WriteLine("POC test Data: " + Guid.NewGuid()); writer.Dispose(); // Get a reference to the blob address, then upload the file to the blob. // Use the value of localFileName for the blob name. CloudBlockBlob cloudBlockBlob = _cloudBlobContainer.GetBlockBlobReference(localFileName); cloudBlockBlob.UploadFromFileAsync(sourceFile); BlobEntry response = new BlobEntry() { BlobContainer = _cloudBlobContainer.Name, FileName = localFileName, Action = "Upload" }; return(Ok(response)); }
public IActionResult DownloadBlob(Guid blobId) { var localPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var localFileName = "naveed-blob-poc_" + blobId + ".txt"; var sourceFile = Path.Combine(localPath, localFileName); var destinationFile = sourceFile.Replace(".txt", "_DOWNLOADED.txt"); CloudBlockBlob cloudBlockBlob = _cloudBlobContainer.GetBlockBlobReference(localFileName); cloudBlockBlob.DownloadToFileAsync(destinationFile, FileMode.Create); BlobEntry response = new BlobEntry() { BlobContainer = _cloudBlobContainer.Name, FileName = localFileName, Action = "Download" }; return(Ok(response)); }
protected virtual EntryState GetItemState(BlobEntry blobInfo, DateTime?changedSince, IList <ThumbnailOption> options) { if (!changedSince.HasValue) { return(EntryState.Added); } foreach (var option in options) { if (!ExistsAsync(blobInfo.Url.GenerateThumbnailName(option.FileSuffix)).GetAwaiter().GetResult()) { return(EntryState.Added); } } if (blobInfo.ModifiedDate.HasValue && blobInfo.ModifiedDate >= changedSince) { return(EntryState.Modified); } return(EntryState.Unchanged); }