Spaces:
Runtime error
Runtime error
Update AzureBlobStorage.py
#18
by Shashika-HF - opened
- AzureBlobStorage.py +25 -15
AzureBlobStorage.py
CHANGED
|
@@ -1,24 +1,27 @@
|
|
| 1 |
from azure.storage.blob import BlobServiceClient
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
storage_account_key="
|
| 5 |
-
storage_account_name="
|
| 6 |
-
connection_string="DefaultEndpointsProtocol=https;AccountName=
|
| 7 |
-
container_name="
|
| 8 |
file_path = r"C:\Users\ASUS\Desktop\UoW\2ND YEAR\SDGP\HuggingFace\Video\production_id_5091624 (1080p).mp4"
|
| 9 |
file_name = "uploaded_video.mp4"
|
| 10 |
|
| 11 |
-
def uploadUserVideoToBlobStorage(file_path,file_name):
|
| 12 |
-
"""Uploads an MP4 video file to the specified Azure Blob Storage container.
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
file_name (str): The desired name of the blob in Azure Blob Storage.
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
try:
|
| 24 |
# Create BlobServiceClient using the connection string
|
|
@@ -35,13 +38,20 @@ def uploadUserVideoToBlobStorage(file_path,file_name):
|
|
| 35 |
# Upload the video data to the blob
|
| 36 |
upload_blob_result = blob_client.upload_blob(data)
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
except FileNotFoundError as e:
|
| 41 |
print(f"Error: File not found at {file_path}.")
|
| 42 |
raise # Re-raise the exception for further handling
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
|
|
|
| 45 |
# Example usage
|
| 46 |
-
uploadUserVideoToBlobStorage(file_path,file_name)
|
|
|
|
|
|
|
| 47 |
|
|
|
|
| 1 |
from azure.storage.blob import BlobServiceClient
|
| 2 |
|
| 3 |
+
# Parameters for linking Azure to the application
|
| 4 |
+
storage_account_key = "zhrGpPBX6PVD+krncC4nVF4yoweEku/z2ErVxjLiuu/CjAVKqM5O4xlGWEyuWGxptL3mA1pv/6P4+AStjSjLEQ=="
|
| 5 |
+
storage_account_name = "useruploadhuggingface"
|
| 6 |
+
connection_string = f"DefaultEndpointsProtocol=https;AccountName={storage_account_name};AccountKey={storage_account_key};EndpointSuffix=core.windows.net"
|
| 7 |
+
container_name = "useruploadhuggingfacevideo"
|
| 8 |
file_path = r"C:\Users\ASUS\Desktop\UoW\2ND YEAR\SDGP\HuggingFace\Video\production_id_5091624 (1080p).mp4"
|
| 9 |
file_name = "uploaded_video.mp4"
|
| 10 |
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
def uploadUserVideoToBlobStorage(file_path, file_name):
|
| 13 |
+
"""Uploads an MP4 video file to the specified Azure Blob Storage container and returns the URL.
|
|
|
|
| 14 |
|
| 15 |
+
Args:
|
| 16 |
+
file_path (str): The path to the MP4 video file.
|
| 17 |
+
file_name (str): The desired name of the blob in Azure Blob Storage.
|
| 18 |
|
| 19 |
+
Returns:
|
| 20 |
+
str: The URL for the uploaded video file in Azure Blob Storage.
|
| 21 |
+
|
| 22 |
+
Raises:
|
| 23 |
+
FileNotFoundError: If the specified file is not found.
|
| 24 |
+
"""
|
| 25 |
|
| 26 |
try:
|
| 27 |
# Create BlobServiceClient using the connection string
|
|
|
|
| 38 |
# Upload the video data to the blob
|
| 39 |
upload_blob_result = blob_client.upload_blob(data)
|
| 40 |
|
| 41 |
+
# Get the URL for the uploaded blob
|
| 42 |
+
blob_url = blob_client.url
|
| 43 |
+
|
| 44 |
+
print(f"Video '{file_name}' uploaded successfully. URL: {blob_url}")
|
| 45 |
+
return blob_url
|
| 46 |
|
| 47 |
except FileNotFoundError as e:
|
| 48 |
print(f"Error: File not found at {file_path}.")
|
| 49 |
raise # Re-raise the exception for further handling
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
+
|
| 53 |
# Example usage
|
| 54 |
+
uploaded_video_url = uploadUserVideoToBlobStorage(file_path, file_name)
|
| 55 |
+
# You can now use the uploaded_video_url for further processing or sharing
|
| 56 |
+
|
| 57 |
|