Запрос GetBlob завершается с ошибкой, когда PutBlob и ListBlob выполняются успешно

Я настроил интеграцию виртуальной сети для своего приложения Python, а также настроил конечную точку службы для учетной записи хранения (также включен брандмауэр виртуальной сети). Запросы Put и List выполняются успешно, но GetBlob не работает, и я не могу просмотреть изображение в своем тестовом приложении:

2.0;2024-07-11T11:32:44.8196257Z;ListBlobs;Success;200;9;6;authenticated;storagecasbx01we;storagecasbx01we;blob;"https:///<endpoint>.blob.core.windows.net:443/cp-images?restype=container&amp;comp=list";"/<endpoint>/cp-images";67d5b517-701e-002a-5086-d3f759000000;0;10.0.0.254:52420;2020-06-12;575;0;220;2956;0;;;;;;"azsdk-python-storage-blob/12.8.1 Python/3.12.2 (Linux-5.15.153.1-2.cm2-x86_64-with-glibc2.31)";;"4a9a9e1e-3f79-11ef-b188-a665be233668";;;;;;;;
2.0;2024-07-11T11:32:51.9590052Z;PutBlob;BlobAlreadyExists;409;5;5;authenticated;storagecasbx01we;storagecasbx01we;blob;"https://<endpoint>.blob.core.windows.net:443/cp-images/NewSmall.png";"/<endpoint>/cp-images/NewSmall.png";67d5cab5-701e-002a-5f86-d3f759000000;0;10.0.0.254:52420;2020-06-12;659;3966;235;220;3966;;"FUj7LV1B0HHctq3t5gmWCA= = ";;;"If-None-Match=*";"azsdk-python-storage-blob/12.8.1 Python/3.12.2 (Linux-5.15.153.1-2.cm2-x86_64-with-glibc2.31)";;"4eeaa860-3f79-11ef-b188-a665be233668";;;;;;;;
2.0;2024-07-11T11:32:52.1686959Z;ListBlobs;Success;200;6;3;authenticated;storagecasbx01we;storagecasbx01we;blob;"https:///<endpoint>.blob.core.windows.net:443/cp-images?restype=container&amp;comp=list";"/<endpoint>/cp-images";67d5cb4f-701e-002a-6786-d3f759000000;0;10.0.0.254:52420;2020-06-12;575;0;220;2956;0;;;;;;"azsdk-python-storage-blob/12.8.1 Python/3.12.2 (Linux-5.15.153.1-2.cm2-x86_64-with-glibc2.31)";;"4f061460-3f79-11ef-b188-a665be233668";;;;;;;;
2.0;2024-07-11T11:33:00.5570855Z;ListBlobs;Success;200;7;2;authenticated;storagecasbx01we;storagecasbx01we;blob;"https:///<endpoint>.blob.core.windows.net:443/cp-images?restype=container&amp;comp=list";"/storagecasbx01we/cp-images";67d5e450-701e-002a-2286-d3f759000000;0;10.0.0.254:52420;2020-06-12;575;0;220;2956;0;;;;;;"azsdk-python-storage-blob/12.8.1 Python/3.12.2 (Linux-5.15.153.1-2.cm2-x86_64-with-glibc2.31)";;"540c6748-3f79-11ef-b188-a665be233668";;;;;;;;
2.0;2024-07-11T11:32:45.3248984Z;GetBlob;AnonymousIpAuthorizationError;403;4;4;anonymous;;storagecasbx01we;blob;"https:///<endpoint>.blob.core.windows.net:443/cp-images/images.png";"/";1392860f-f01e-000b-4186-d3d322000000;0;163.116.166.103:8762;2009-09-19;624;0;105;246;0;;;;;;"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36";"https://<app_service>.azurewebsites.net/";;;;;;;;;
2.0;2024-07-

Часть кода Python:

@app.route("/")
def view_photos():
    blob_items = container_client.list_blobs() # list all the blobs in the container

    img_html = "<div style='display: flex; justify-content: space-between; flex-wrap: wrap;'>"

    for blob in blob_items:
        blob_client = container_client.get_blob_client(blob=blob.name) # get blob client to interact with the blob and get blob url
        img_html += "<img src='{}' width='auto' height='200' style='margin: 0.5em 0;'/>".format(blob_client.url) # get the blob url and append it to the html
    
    img_html += "</div>"

    # return the html with the images
    return """
    <head>
    <!-- CSS only -->
        <link href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel = "stylesheet" integrity = "sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin = "anonymous">
    </head>
    <body>
        <nav class = "navbar navbar-expand-lg navbar-dark bg-primary">
            <div class = "container">
                <a class = "navbar-brand" href = "/">Photos App</a>
            </div>
        </nav>
        <div class = "container">
            <div class = "card" style = "margin: 1em 0; padding: 1em 0 0 0; align-items: center;">
                <h3>Upload new File</h3>
                <div class = "form-group">
                    <form method = "post" action = "/upload-photos" 
                        enctype = "multipart/form-data">
                        <div style = "display: flex;">
                            <input type = "file" accept = ".png, .jpeg, .jpg, .gif" name = "photos" multiple class = "form-control" style = "margin-right: 1em;">
                            <input type = "submit" class = "btn btn-primary">
                        </div>
                    </form>
                </div> 
            </div>
        
    """ + img_html + "</div></body>"

А также интеграция виртуальной сети правильно работает с запросами Put и List (так что у меня есть частный исходящий IP-адрес. Но для запроса Get отображается общедоступный IP-адрес. Может ли smbd помочь с этим, потому что действительно застрял :(

Как установить LAMP Stack - Security 5/5 на виртуальную машину Azure Linux VM
Как установить LAMP Stack - Security 5/5 на виртуальную машину Azure Linux VM
В предыдущей статье мы завершили установку базы данных, для тех, кто не знает.
Как установить LAMP Stack 1/2 на Azure Linux VM
Как установить LAMP Stack 1/2 на Azure Linux VM
В дополнение к нашему предыдущему сообщению о намерении Azure прекратить поддержку Azure Database для MySQL в качестве единого сервера после 16...
0
0
64
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

При использовании вашего кода blob_client.url изображения не загружались. Вместо использования blob_client.url я использовал URL-адрес SAS каждого большого двоичного объекта, который мне подходил.

Ниже приведенный код работал у меня.

Я создал токен SAS и настроил URL-адрес.

from flask import Flask, render_template
from datetime import timedelta,datetime
from azure.storage.blob import BlobServiceClient, generate_blob_sas,BlobSasPermissions

app = Flask(__name__)

account_name = "xxxxxxxxxxxxxxx"
container_name = "xxxxxxxxxxxxx"
key  = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

connection_string = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

blobservice_client= BlobServiceClient.from_connection_string(connection_string)
container_client= blobservice_client.get_container_client(container_name)

def gernrate_blob_sas_url(blob_name):
    sas = generate_blob_sas(
            account_name= account_name,
            account_key= key,
            container_name= container_name,
            blob_name= blob_name,
            permission=BlobSasPermissions(read=True),
            expiry= datetime.now() + timedelta(hours=1)
        )
    sas_url =f"https://{account_name}.blob.core.windows.net/{container_name}/{blob_name}?{sas}"
    return sas_url

@app.route('/')
def index():
    blob_items = container_client.list_blobs() # list all the blobs in the container

    img_html = "<div style='display: flex; justify-content: space-between; flex-wrap: wrap;'>"

    for blob in blob_items:
        blob_sasurl=gernrate_blob_sas_url(blob.name)         # get blob client to interact with the blob and get blob url
        img_html += "<img src='{}' width='auto' height='200' style='margin: 0.5em 0;'/>".format(blob_sasurl) # get the blob sas url and append it to the html
    
    img_html += "</div>"

    # return the html with the images
    return """
    <head>
    <!-- CSS only -->
        <link href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel = "stylesheet" integrity = "sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin = "anonymous">
    </head>
    <body>
        <nav class = "navbar navbar-expand-lg navbar-dark bg-primary">
            <div class = "container">
                <a class = "navbar-brand" href = "/">Photos App</a>
            </div>
        </nav>
        <div class = "container">
            <div class = "card" style = "margin: 1em 0; padding: 1em 0 0 0; align-items: center;">
                <h3>Upload new File</h3>
                <div class = "form-group">
                    <form method = "post" action = "/upload-photos" 
                        enctype = "multipart/form-data">
                        <div style = "display: flex;">
                            <input type = "file" accept = ".png, .jpeg, .jpg, .gif" name = "photos" multiple class = "form-control" style = "margin-right: 1em;">
                            <input type = "submit" class = "btn btn-primary">
                        </div>
                    </form>
                </div> 
            </div>
        
    """ + img_html + "</div></body>"
if __name__ = = "__main__":
    app.run()

OUTPUT:

До :

После :

Эти собаки такие милые...

wenbo 12.07.2024 09:40

да, спасибо @wenbo

Vivek Vaibhav Shandilya 12.07.2024 09:43

Другие вопросы по теме