【Azure】微软云文件存储

文章目录

Blob文件

创建存储账户

https://portal.azure.com/#view/Microsoft_Azure_StorageHub/StorageHub.MenuView/~/StorageAccountsBrowse

创建

添加容器

填写名称

在线查看文件

使用Python读取、写入

https://learn.microsoft.com/zh-cn/python/api/overview/azure/storage-blob-readme?view=azure-python

shell 复制代码
# pip install azure-storage-blob
from pathlib import Path

from azure.storage.blob import BlobClient


class AzureStore:
    def __init__(self, connection_string: str, container_name: str, save_path: Path):
        """

        Args:
            connection_string: Azure存储凭证
            container_name: 容器名称
            save_path: 文件保存初始化目录
        """
        self.connection_string = connection_string
        self.container_name = container_name
        self.save_path = save_path
        Path(self.save_path).mkdir(parents=True, exist_ok=True)

    def upload(self, file_path: Path):
        # file_path = Path("./1.txt")
        blob = BlobClient.from_connection_string(conn_str=self.connection_string, container_name=self.container_name, blob_name=file_path.name)

        with open(file_path, "rb") as f:
            blob.upload_blob(f)

    def download(self, blob_name: str):
        blob = BlobClient.from_connection_string(conn_str=self.connection_string, container_name=self.container_name, blob_name=blob_name)

        with open(Path(self.save_path).joinpath(blob_name), "wb") as f:
            blob_data = blob.download_blob()
            blob_data.readinto(f)
if __name__ == '__main__':
    connection_string = "<访问密钥中的连接字符串>"
    store = AzureStore(connection_string, "<容器名称>", Path("./"))
    store.download("1.txt")

其他语言JAVA、Net、Spring等

JAVA:https://learn.microsoft.com/zh-cn/azure/storage/common/storage-samples-java?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json

NET:https://learn.microsoft.com/zh-cn/azure/storage/common/storage-samples-dotnet?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json

经典文件

同理

Python文档

https://learn.microsoft.com/zh-cn/python/api/overview/azure/storage-file-share-readme?view=azure-python

shell 复制代码
# pip install azure-storage-file-share
from pathlib import Path

from azure.storage.fileshare import ShareFileClient

"""
经典文件共享
"""
class AzureFileShareStore:
    def __init__(self, connection_string: str, share_name: str, save_path: Path):
        """

        Args:
            connection_string: Azure存储凭证
            container_name: 经典文件共享名称
            save_path: 文件保存初始化目录
        """
        self.connection_string = connection_string
        self.share_name = share_name
        self.save_path = save_path
        Path(self.save_path).mkdir(parents=True, exist_ok=True)

    def upload(self, file_path: Path, store_path: str):
        file_client = ShareFileClient.from_connection_string(conn_str=self.connection_string, share_name=self.share_name, file_path=store_path)

        with open(file_path, "rb") as f:
            file_client.upload_file(f)

    def download(self, store_path: str):
        file_client = ShareFileClient.from_connection_string(conn_str=self.connection_string, share_name=self.share_name, file_path=store_path)

        with open(Path(self.save_path).joinpath(Path(store_path).name), "wb") as f:
            data = file_client.download_file()
            data.readinto(f)


if __name__ == '__main__':
     connection_string = "<访问密钥中的连接字符串>"
    store = AzureStore(connection_string, "<经典文件创建的名称>", Path("./"))
    store.download("1.txt")
相关推荐
circuitsosk9 小时前
AI输出的“质检员”:构建智能体质量评估、异常检测与人工兜底的三层防线
人工智能·python·microsoft·正则表达式·langchain
TunerT_TQ11 小时前
Microsoft 微软 Fluent UI 源码静态评测:从工程结构、测试线索到交付治理的完整解读
microsoft·开源·github
TunerT_TQ12 小时前
Microsoft 微软 AI-For-Beginners 静态评测:一套 AI 入门课程,为什么不能只按代码仓库来评价?
microsoft·开源·github
行业研究员13 小时前
腾讯云ADP:智能体平台封神榜
人工智能·microsoft·腾讯云·智能体·智能体平台·腾讯云adp
张宇Joaquin18 小时前
高性能计算之MPI——集合通信漫谈
服务器·microsoft·asp.net
树码小子2 天前
Python 超轻量 Web 框架 Flask 快速入门教程
前端·python·flask
qq_22589174663 天前
基于Flask的城市地铁客流量数据预测系统设计与实现
后端·python·flask
梦想的旅途23 天前
企业微信 API 二次开发:AI 智能体与外部群业务流闭环
人工智能·microsoft·企业微信
zhiSiBuYu05174 天前
Flask Session 与 Cookie 新手实战指南
后端·python·flask