How to import csv file( already uploaded in bl

2019-08-26 09:27发布

I want to import csv file(already uploaded in blob storage) in Azure.

For example I have uploded test.csv on blob storage, now i just want to import that test.csv file in .net(azure) and after importing i will insert that data into azure database. I am using C# .net. Please suggest how can I acheive this. I want to follow belwo steps:-

  1. Creating a cvs file with all rows.
  2. Upload it as blob.
  3. Parse it with a Worker role and insert it in the sql azure db.

Thanks.

1条回答
放荡不羁爱自由
2楼-- · 2019-08-26 09:33

A bit more clarification around your question would be helpful. Are you trying to upload a file to Azure blob storage? Download it from there for your app to consume? What language(s) are you using?

There are plenty of examples of loading files into and pulling them from Azure blob storage using .NET at least a handful for doing it with Java or PHP.

I you can clarify what you're trying to do, I'd be happy to point you at the appropriate ones. :)

-- answer based on comment update -- The steps for retrieving the blob are fairly straight forward: 1) create your Azure storage client using your azure storage credentials add a using clause:

using Microsoft.WindowsAzure.StorageClient;

get a client for accessing blob storage:

CloudBlobClient tmpClient = new CloudBlobClient("<nameofyourconfigsetting>");

get a referrence to the blob you want to download:

CloudBlob myBlob = tmpClient.GetBlobReference("container/myblob.csv");

2) read the blob & save to a file

myBlob.DownloadToFile("<path>/myblob.csv");

The save location can be the %temp% location or if its a large file you may want to allocate some local storage space and put it there. The other thing you want to keep in mind is that if you are doing this in a role instance, you'll need to make sure you have measures in place to prevent two instances from concurrently trying to process the same file. If the file is small enough, you can probably even keep it as a memory stream and process it that way. If this is the case, you can use the DownloadToStream property of the CloudBlob object.

For additionally reading, I'd recommend checking out the MSDN library for the details on the StorageClient and CloudBlob contains. Additionally, the Windows Azure Platform Training Kit has some good labs to help you get a better understanding of how Azure Storage works.

查看更多
登录 后发表回答