WindowsAzure.Storage
portal.azure.com
Storage Accounts
-> Access Key
public string StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=azurestudentsdiag959;AccountKey=yYLvvu+cHBGK/sBLIvbYkVzE/VBS+z5Tw4K5komw2ybyvFYIV7ilKtYZnfa7rYQwUvTSrmFniX9QNrLyq9y3sQ==;EndpointSuffix=core.windows.net";
Create
, Edit
// Update file lên thư mục Storage Azure // Create Reference to Azure Storage Account String strorageconn = this.StorageConnectionString; CloudStorageAccount storageacc = CloudStorageAccount.Parse(strorageconn); //Create Reference to Azure Blob CloudBlobClient blobClient = storageacc.CreateCloudBlobClient(); //The next 2 lines create if not exists a container named "democontainer" CloudBlobContainer container = blobClient.GetContainerReference("democontainer"); container.CreateIfNotExists(); //The next 7 lines upload the file test.txt with the name DemoBlob on the container "democontainer" CloudBlockBlob blockBlob = container.GetBlockBlobReference(_FileName); blockBlob.UploadFromStream(image.InputStream);Tham khảo code: https://github.com/kellyfire611/learning.nentang.vn-asp.net/blob/master/WebBanHang/WebBanHang/Controllers/Backend/ProductsController.cs
/// <summary> /// Hàm lấy đường dẫn URL từ Storage Azure /// </summary> /// <returns>Image URL</returns> public string GetImageUrlFromAzureStore() { string blobUrl = ""; // Update file lên thư mục Storage Azure // Create Reference to Azure Storage Account String strorageconn = this.StorageConnectionString; CloudStorageAccount storageacc = CloudStorageAccount.Parse(strorageconn); //Create Reference to Azure Blob CloudBlobClient blobClient = storageacc.CreateCloudBlobClient(); //The next 2 lines create if not exists a container named "democontainer" CloudBlobContainer container = blobClient.GetContainerReference("democontainer"); //The next 7 lines upload the file test.txt with the name DemoBlob on the container "democontainer" CloudBlockBlob blockBlob = container.GetBlockBlobReference(this.image); // hoahong.jpg blobUrl = blockBlob.Uri.AbsoluteUri; //https://azure.storage.com/kellyfire/democontainer/hoahong.jpg return blobUrl; }Tham khảo code: https://github.com/kellyfire611/learning.nentang.vn-asp.net/blob/master/WebBanHang/WebBanHang/EF/productsExtends.cs
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!