blob-adapter_2.py 1.1 KB

12345678910111213141516171819202122
  1. def upload(self, file_dict):
  2. upload_response = {}
  3. for key in file_dict:
  4. print("File Dict Key: [{}] value is: {}".format(key, file_dict[key]))
  5. print("\nUploading to Azure Storage as blob:\n\t" + key)
  6. self.blob_client = self.blob_service_client.get_blob_client(container=self.get_config('container_name'), blob=key)
  7. with open(file_dict[key], "rb") as data:
  8. try:
  9. self.blob_client.upload_blob(data)
  10. print('File: Uploaded Successfully: {}'.format(key))
  11. upload_response[key] = 'Successfully Uploaded'
  12. except ResourceExistsError:
  13. print('File: NOT Uploaded Successfully: {}'.format(key))
  14. upload_response[key] = 'This Resource already exists'
  15. upload_response['Partial'] = True
  16. print('This Resource already exists')
  17. # return 'This Resource already exists'
  18. print("Before Returning Response:")
  19. print(jsonify(upload_response))
  20. print("---------------")
  21. return upload_response