开发者

Is there a way to obtain the link of files stored on cloud?

开发者 https://www.devze.com 2023-04-10 01:14 出处:网络
I am developing a cloud application for my project. I want to provide the facility of storing files 开发者_开发百科on the cloud and retrieving those files after a valid log in.

I am developing a cloud application for my project. I want to provide the facility of storing files 开发者_开发百科on the cloud and retrieving those files after a valid log in.

I want to store the links of the actual cloud based files in a database. Is there any way of knowing the links of the files on the cloud if the cloud that I will be using is a Microsoft Cloud?

Thank you.


When you create your Azure Storage account you need to givet it a name. Let's say you name it foostorage. Then if you would upload a blob using the following code.

string path = "folder"
string fileName = "file.txt";

CloudBlobContainer container = blobClient.GetContainerReference(path);
var blobContainerPermissions = new BlobContainerPermissions
    {
       PublicAccess = BlobContainerPublicAccessType.Container
    };
container.CreateIfNotExist();
container.SetPermissions(blobContainerPermissions);

 CloudBlob blob = container.GetBlobReference(fileName);     
 blob.UploadText("Text to be saved to blob storage");

 string blobUri = blob.Uri.AbsoluteUri;

Then blobUri would get the value https://foostorage.blob.core.windows.net/folder/file.txt Please note that the access rights is set to public.


Here's a sample which shows how to store files in Azure blob storage.

It also retrieves the uri of the files and then shows it on a web page. You could easily do the same and store in a DB.

http://soumya.wordpress.com/2010/05/19/azure-simplified-part3-using-azure-blob-storage/

BTW, that tutorial is using local development storage called devfabric which is why you see the local address 127.0.0.1 in the url. If you have a real azure cloud account, the code will be the same.

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消