Home > Mobile >  Overwrite a blob on Blob Storage - getting "read only" exception
Overwrite a blob on Blob Storage - getting "read only" exception

Time:10-06

I want to overwrite a blob myfile.txt on Azure Blob Storage. I use this code, where blob_url contains the SAS token. The blob has access level "private".

However, I always get this error:

Result: Failure Exception: OSError: [Errno 30] Read-only file system: './TimerTrigger1/myfile.txt' Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 402, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 606, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper result = function(**args) File "/home/site/wwwroot/TimerTrigger1/__init__.py", line 32, in main open(filename, 'wb').write(r.content)

This is my code in Python:

blob_url = "https://me.blob.core.windows.net/mycontainer/myfile.txt?sp=r&st=2021-10-05T14:07:24Z&se=2021-10-05T22:07:24Z&spr=https&sv=2020-08-04&sr=b&sig=asdfasdfasdfa"
blob_client = BlobClient.from_blob_url(
    blob_url=blob_url
)
with open("myfile.txt", "rb") as blob_file:
    blob_client.upload_blob(data=blob_file)

Any ideas on how to make that happen?

CodePudding user response:

This is because you only have read permission in your SAS token (sp=r). In order to update the blob, you will also need write permission in your token.

Please create a SAS token with both read and write permission and you should be able to update the blob. Your SAS URL should look something like:

https://me.blob.core.windows.net/mycontainer/myfile.txt?sp=rw&st=2021-10-05T14:07:24Z&se=2021-10-05T22:07:24Z&spr=https&sv=2020-08-04&sr=b&sig=asdfasdfasdfa
  • Related