从 django REST API 视图中,我尝试访问存储在 azure 存储 blob 中的文件。我想打开它而不将其下载到文件中,如此处所示。读取访问权限就足够了。
为此,我这样勾勒出我的观点:
import os
from fsspec.implementations.http import HTTPFileSystem
@api_view()
def my_view(request):
url = "https://storageaccount.blob.core.windows.net/container/"
filename = "file.f"
fs = HTTPFileSystem(
container_name=os.environ["AZURE_STORAGE_CONTAINER"],
storage_options={
"account_name": os.environ["AZURE_STORAGE_ACCOUNT"],
"account_key": os.environ["AZURE_STORAGE_KEY"],
},
)
with fs.open(url + filename, "r") as fobj:
ds = somehow.open_dataset(fobj)
return Response({"message": "Data manipulated"}, status=200)
Run Code Online (Sandbox Code Playgroud)
这会给出 FileNotFoundError。
我的问题是:
filesystems django azure django-rest-framework azure-blob-storage