Spaces:
Runtime error
Runtime error
Update AzureBlobStorageVideo.py
Browse files- AzureBlobStorageVideo.py +25 -6
AzureBlobStorageVideo.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 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\
|
| 9 |
-
file_name = "
|
| 10 |
|
| 11 |
|
| 12 |
|
|
@@ -64,6 +65,27 @@ def uploadUserVideoToBlobStorage(file_path, file_name):
|
|
| 64 |
print(f"Error: File not found at {file_path}.")
|
| 65 |
raise # Re-raise the exception for further handling
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
if __name__ == "__main__":
|
| 68 |
# Example usage
|
| 69 |
uploaded_video_url = uploadUserVideoToBlobStorage(file_path, file_name)
|
|
@@ -74,6 +96,3 @@ if __name__ == "__main__":
|
|
| 74 |
|
| 75 |
# Pass container_client and file_name to the deletion function
|
| 76 |
deleteUserVideoFromBlobStorage(container_client,file_name)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
| 1 |
+
from azure.storage.blob import BlobServiceClient, generate_blob_sas, BlobSasPermissions
|
| 2 |
+
from datetime import datetime, timedelta
|
| 3 |
|
| 4 |
# Parameters for linking Azure to the application
|
| 5 |
storage_account_key = "zhrGpPBX6PVD+krncC4nVF4yoweEku/z2ErVxjLiuu/CjAVKqM5O4xlGWEyuWGxptL3mA1pv/6P4+AStjSjLEQ=="
|
| 6 |
storage_account_name = "useruploadhuggingface"
|
| 7 |
connection_string = f"DefaultEndpointsProtocol=https;AccountName={storage_account_name};AccountKey={storage_account_key};EndpointSuffix=core.windows.net"
|
| 8 |
container_name = "useruploadhuggingfacevideo"
|
| 9 |
+
#file_path = r"C:\Users\isuru\Documents\IIT University\Modules\Year 2 - Semester 2\SDGP\HapticAudio SE09 Local Repo\gradio-env\HapticsProject\video\WIND ANIMATION.mp4"
|
| 10 |
+
#file_name = "wind_video.mp4"
|
| 11 |
|
| 12 |
|
| 13 |
|
|
|
|
| 65 |
print(f"Error: File not found at {file_path}.")
|
| 66 |
raise # Re-raise the exception for further handling
|
| 67 |
|
| 68 |
+
|
| 69 |
+
def generateSASToken(account_name,container_name, blob_name, account_key):
|
| 70 |
+
sas_token = generate_blob_sas(account_name=account_name,
|
| 71 |
+
container_name=container_name,
|
| 72 |
+
blob_name=blob_name,
|
| 73 |
+
account_key=account_key,
|
| 74 |
+
permission=BlobSasPermissions(read=True),
|
| 75 |
+
expiry=datetime.utcnow() + timedelta(hours=1))
|
| 76 |
+
|
| 77 |
+
print(f"SAS Token generated:{sas_token}")
|
| 78 |
+
|
| 79 |
+
return sas_token
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def generateSASURL(account_name, container_name, blob_name, sas_token):
|
| 83 |
+
|
| 84 |
+
sas_url = 'https://' + account_name + '.blob.core.windows.net/' + container_name + '/' + blob_name + '?' + sas_token
|
| 85 |
+
print(f"SAS URL Generated: {sas_url}")
|
| 86 |
+
|
| 87 |
+
return sas_url
|
| 88 |
+
|
| 89 |
if __name__ == "__main__":
|
| 90 |
# Example usage
|
| 91 |
uploaded_video_url = uploadUserVideoToBlobStorage(file_path, file_name)
|
|
|
|
| 96 |
|
| 97 |
# Pass container_client and file_name to the deletion function
|
| 98 |
deleteUserVideoFromBlobStorage(container_client,file_name)
|
|
|
|
|
|
|
|
|