I am having a problem updating a csv file in my blob. I have an existing file inside my blob which is a CSV file, and when I press the download button it will automatically download the file to my machine.
Now I already created a Logic App that will update the csv file. When I run the trigger of the app, it updates the file but when I press download, it opens up a new tab where the csv file will be displayed.
I want it the way like the original when I press download it download the file to my machine.
Any help will do or verification if this is possible.
I already tried "compose" and "create to csv" but this way it will not store it to a blob.
As I have test, when you want to create a .csv file with "create blob" action in logic app, it will always get the same problem with you. Because the blob content is "text/plan" which will display in another tab to show.
So, I suggest that you could use azure function to create the blob. In azure function you could set:blob.Properties.ContentType = "application/octet-stream";
Here is the create blob method in azure function:
storageAccount = CloudStorageAccount.Parse(connectionString);
client = storageAccount.CreateCloudBlobClient();
container = client.GetContainerReference("data");
await container.CreateIfNotExistsAsync();
blob = container.GetBlockBlobReference(name);
blob.Properties.ContentType = "application/octet-stream";
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
{
await blob.UploadFromStreamAsync(stream);
}
For more detailed code, you could refer to this article. After following that, you could download your blob in your local machine.
Note: when you create the azure function action in logic app, it will show error. Just delete Appsetting of "AzureWebJobsSecretStorageType" to "blob".
Related
So I want to create a python function that creates an inmemory text file that I can pass a string, or multiple strings to and upload to azure blob storage. Doing it with a normal text file is a novel task, but I can't seem to get it happen using the io module.
Please check out this https://pypi.org/project/azure-storage-blob/ which given in detail upload a file to azure blob storage by doing the following.
You can easily pass the string to upload_blob method using python as below:
blob = BlobClient.from_connection_string(conn_str="<connection_string>", container_name="my_container", blob_name="my_blob")
data = "test"
blob.upload_blob(data)
I have a issue trying to delete a "folder" (blob) from Azure Blob Storage. I have a container and inside that container multiple "folders" (blobs) than contain a big amount of "files" blobs inside.
So, for example, if I have a file called test.pdf inside a blob "folder" called 1234 and I go to search the "file" blob /1234/test.pdf, I'm able to find it, download it or delete it. But if I search for the blob "folder" /1234/ I always get an error saying that the blob doesn't exist "404 BlobNotFound The specified blob does not exist".
This is the code I'm using:
BlobURL blobURL = containerUrl.createBlobURL(folderName+"/"+fileName);
blobURL.download().blockingGet();
blobURL.delete().blockingGet(); //It Works
BlobURL blobURL = containerUrl.createBlobURL(folderName+"/");
blobURL.download().blockingGet();
blobURL.delete().blockingGet(); // Did not works
BlobURL blobURL = containerUrl.createBlobURL(folderName);
blobURL.download().blockingGet();
blobURL.delete().blockingGet(); // Did not works
Any advice? Thanks in advance!
If you are using createBlobUrl it should be a valid url of the blob which refers to the actual blob. If you want to access all the blobs inside a contianer, you should use
var blobList= container.ListBlobs(prefix: "folderName/", useFlatBlobListing: true);
I have saved pdf files in azure blob storage blob, I want to show these files on my website but when a file render on html its link should be deactivated means no one can use that link to download the file again. Is this possible in azure blob storage?
You can use the blob policy to make it:
CloudStorageAccount account = CloudStorageAccount.Parse("yourStringConnection");
CloudBlobClient serviceClient = account.CreateCloudBlobClient();
var container = serviceClient.GetContainerReference("yourContainerName");
container
.CreateIfNotExistsAsync()
.Wait();
CloudBlockBlob blob = container.GetBlockBlobReference("test/helloworld.txt");
blob.UploadTextAsync("Hello, World!").Wait();
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
// define the expiration time
policy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1);
// define the permission
policy.Permissions = SharedAccessBlobPermissions.Read;
// create signature
string signature = blob.GetSharedAccessSignature(policy);
// get full temporary uri
Console.WriteLine(blob.Uri + signature);
If I understand correctly, you're looking for single use links to Azure Blobs. Natively this feature is not available in Azure Storage. You would need to write code to implement something like this where you would keep track of the number of times a link has been used and in case the limit exceeds, you will not process that link.
My plan is to have the WebJob send the newly generated CSV to a blob storage where it's picked up by an Azure Function and emailed out to a group of recipients.
I'm using the CsvWriter library to generate the CSV. I'm told that ideally I should upload straight to the blob storage container, however I'm not sure how I'm going to do that when CsvWriter is only able to write to the filesystem using whatever TextWriter we pass to it through the constructor.
So what I'm trying to do instead is allow CsvWriter to write the file to the filesystem, and then I'll pick that up and upload it to the blob storage. The problem here is that every directory I try to get it to write to denies access to be WebJob. I have tried Environment.GetEnvironmentVariable("WEBJOBS_ROOT_PATH") as well as %HOME% and d:\site\wwwroot.
What directory do I need to be writing to?
You can avoid it altogether by using a StringWriter, you do not have to use the file system:
using (var stringWriter = new StringWriter())
using (var csvWriter = new CsvHelper.CsvWriter(stringWriter))
{
csvWriter.WriteComment("Test");
csvWriter.Flush();
var blob = container.GetBlockBlobReference("test.csv");
await blob.UploadTextAsync(stringWriter.ToString());
}
Just started working on with Windows Azure and Mapreduce. I've already created an HDInsight cluster within the Azure Portal and also created a Block Blob using the Azure Explorer named BlobFiles.
What I wanted to know is, is there a way of listing all the files within a Blob which is within a Blob Container? In other words if I'm uploading text files as well as images to the same Blob, how could I list those text files as well as those images programmatically or in another way?
Searched for a solution, but still couldn't come across of one. I'm able to see the content of the file individually using the Azure Explorer, where as um unable to find a way to see or display the files within that particular Blob!
Edited:
This is what I've tried to display the Blobs:
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("fyptest1");
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");
lboxblob.ItemsSource = container.ListBlobs();//lboxblob is the name of my listbox
When I tried the above code it displays something like Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob, and so on for a few number of times.
Any help would be appreciated.
Each Azure storage "blob" is a "file." You want to list the "blobs" in a "blob container," most likely.
To do this, use the CloudBlobContainer.ListBlobs() method.
https://msdn.microsoft.com/en-us/library/azure/dd135734.aspx
That is because the binding would end up calling ToString on every list item returned, which just displays the type name. If you would like to see URIs in your list box instead, please change the last line to:
lboxblob.ItemsSource = container.ListBlobs().Select(b => b.Uri);
But please refer to the other answer for the correct terminology. As others mentioned, blobs do not contain other objects like files.