Skip to content

Commit

Permalink
Merge pull request #18 from ks6088ts-labs/cosmetic-changes
Browse files Browse the repository at this point in the history
breaking change: update blob service
  • Loading branch information
ks6088ts authored Oct 18, 2024
2 parents 4d614d2 + d8bae8b commit 1eef40e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/scenarios/1_azure_iot_hub_messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Here are the steps to configure IoT Hub file uploads: [Configure IoT Hub file up
## Edge device

To understand how to use the Azure IoT Hub SDK for Python, we provide a script which is supposed to run on the edge device. This demonstrates how to utilize the SDK to send and receive messages from the Azure IoT Hub.
To implement features around the Azure IoT Hub, you can refer to the following scripts.

- [Samples for the Azure IoT Hub Device SDK](https://github.com/Azure/azure-iot-sdk-python/tree/main/samples)

### Upload a file to the Azure Blob Storage

Expand Down
2 changes: 1 addition & 1 deletion tests/test_blob_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_main():

# list_images
response = client.get(
url=path_format.format("/images"),
url=path_format.format("/"),
)
assert response.status_code == 200
logger.info(f"response: {response.json()}")
39 changes: 27 additions & 12 deletions workshop_azure_iot/routers/blob_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,31 @@


@router.get(
"/images/{blob_name}",
responses={200: {"content": {"image/jpeg": {}}}},
"/{blob_name}",
response_class=Response,
)
async def get_image(
async def get_blob(
blob_name: str,
):
image_bytes = client.download_blob_stream(
blob_name=blob_name,
)
return Response(
content=image_bytes,
media_type="image/jpeg",
content=client.download_blob_stream(
blob_name=blob_name,
),
)


@router.get(
"/images",
"/",
)
async def list_images():
async def list_blobs():
return client.list_blobs()


@router.post(
"/images",
"/",
status_code=201,
)
async def upload_image(
async def upload_blob(
file: UploadFile,
blob_name: str,
):
Expand All @@ -63,3 +60,21 @@ async def upload_image(
"etag": response.get("etag"),
},
)


@router.get(
"/images/{device_name}/{file_name}",
responses={200: {"content": {"image/jpeg": {}}}},
response_class=Response,
)
async def get_image(
device_name: str,
file_name: str,
):
image_bytes = client.download_blob_stream(
blob_name=f"{device_name}/{file_name}",
)
return Response(
content=image_bytes,
media_type="image/jpeg",
)

0 comments on commit 1eef40e

Please sign in to comment.