def block_blob_service(self): from azure.storage.blob import BlockBlobService, PublicAccess block_blob_service = BlockBlobService( connection_string=self.conn_string, socket_timeout=self.socket_timeout, ) if self.max_block_size is not None: block_blob_service.MAX_BLOCK_SIZE = self.max_block_size if self.max_block_size is not None: block_blob_service.MAX_SINGLE_PUT_SIZE = self.max_single_put_size if self.create_if_missing: block_blob_service.create_container( self.container, public_access=PublicAccess.Container if self.public else None) return block_blob_service
def upload_recording(filename: str, config): upload_light = led.led(16) # GPIO 20 is the Uploading indicator upload_light.on() try: logger.write('Uploading status file...') status_file = status.update_status(False, True, False) status.upload_status(status_file, False) logger.write('Upload complete.') except Exception as e: logger.write('An error occurred while uploading a status file.') logger.write(str(e)) try: start = time.time() logger.write('Uploading...') credential_path = 'credentials.ini' credentials = configparser.ConfigParser() credentials.read(credential_path) container = config.get('Cloud', 'container') username = credentials.get('Azure', 'Username') password = credentials.get('Azure', 'Password') block_blob_service = BlockBlobService(account_name=username, account_key=password) # Force chunked uploading and set upload block sizes to 8KB block_blob_service.MAX_SINGLE_PUT_SIZE=16 block_blob_service.MAX_BLOCK_SIZE=8*1024 timestamp = os.path.basename(filename).split('.')[0] extension = os.path.basename(filename).split('.')[1] timestamp_day = timestamp.split('_')[1] timestamp_time = timestamp.split('_')[2] timestamp_day = timestamp_day.replace('-', '_') timestamp_time = timestamp_time.replace('-', '_') blob_name = timestamp_day + '/' + timestamp_time + '/recording.' + extension block_blob_service.create_blob_from_path(container, blob_name, filename) end = time.time() elapsed = end - start logger.write('Upload Succeeded: ' + blob_name) logger.write('Upload took ' + str(elapsed) + ' seconds.\n') if REMOVE_RECORDINGS: os.remove(filename) except Exception as e: logger.write('CheckConfig: There was an error uploading to the cloud.') logger.write(str(e)) upload_light.off() return upload_light.off() logger.write('Upload complete') try: logger.write('Uploading status file...') status_file = status.update_status(False, False, False) status.upload_status(status_file, False) logger.write('Upload complete.') except Exception as e: logger.write('An error occurred while uploading a status file.') logger.write(str(e))