Comments (1)
from azure.storage.blob import ContainerClient
import os
import json
import datetime
import time
def file_upload_blob(sitename, property_list, location="", containername=os.getenv('containerName')):
try:
# connect to the container client.
container_client = ContainerClient.from_connection_string(
conn_str=os.getenv("BLOB_STORAGE_CONNECTION_STRING"),
container_name=containername
)
time.sleep(3)
logger.info(f"connected to the container {containername}")
# perform file operations
filename = os.path.join(sitename,
"{sn}_{location}{ts}.json".format(
ts=datetime.datetime.now().strftime(r'%Y-%b-%d_%H-%M-%S'),
sn=sitename,
location=location)
)
try:
if property_list:
container_client.upload_blob(
name=filename,
data=json.dumps(obj=property_list, indent=4),
blob_type='BlockBlob',
timeout=3600 # Set a longer timeout in seconds (1 hour in this example)
)
logger.info(f'file "{filename}" has been uploaded in azure blob storage')
else:
container_client.upload_blob(
name=filename,
data=json.dumps(obj=['got empty file'], indent=4),
blob_type='BlockBlob',
timeout=3600 # Set a longer timeout in seconds (1 hour in this example)
)
logger.info('found empty file! .. uploading empty file')
except Exception as e:
logger.error(f"getting error while uploading file to blob storage:{e}")
traceback.print_exc()
except Exception as e1:
logger.error(f" blob storage error: {e1}")
# Call the function with appropriate parameters
# file_upload_blob(sitename, property_list, location, containername)
the timeout parameter in the upload_blob method has been set to 3600 seconds (1 hour) to allow longer time for the upload operation to complete
from azure-storage-python.
Related Issues (20)
- QueueServiceClient.get_queue_client does not inherit credentials
- new feature request: adding unix style globbing tool to list files on azure blobs
- https://github.com/Azure/azure-storage-python has no package.swift manifest
- get md5 for blob HOT 1
- BlobClient, BlobServiceClient, ContainerClient cannot be imported HOT 1
- `exists` method for the async blob client leaks file descriptors
- Large File Upload Max_Conncurrenct HOT 1
- How to check if blob is directory
- Please fix mypy issues HOT 5
- ModuleNotFoundError: No module named 'azure.storage.cloudstorageaccount' HOT 2
- Cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup' HOT 3
- new version cryptography dependency crashes app
- Streaming blob to client side ?
- Include millisecond component (%f) in datetime serialization
- This repo is missing important files
- How to handle timeout for Uploading a blob in Azure Storage using Python SDK? HOT 1
- ModuleNotFoundError: No module named 'azure.storage'
- problem with python get_file_properties HOT 2
- Create symlink via azure.storage.file FileService
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-storage-python.