1

I am storing images on Azure storage. BUt after storing images when I am trying to access bob url it is giving me access denied error.

My code :

block_blob_service = BlockBlobService(account_name=ACCOUNT_NAME, account_key=ACCOUNT_KEY)
block_blob_service.create_container('organisation', public_access=PublicAccess.Container)

org = Organisation.objects.get(pk=34)
image = download_image(org.org_logo.url)
bob = block_blob_service.create_blob_from_path(
        'organisation',
        org.name,
        image,
        content_settings=ContentSettings(content_type='image/png')
                )

image_url = block_blob_service.make_blob_url('organisation', org.name) **# same url is accessible via browser but not from script**

org.org_logo = image_url  **# this is giving error of access denied**
org.save()

I am not sure but I think need to edit CORS settings of my storage , but I am not able to figure out where to edit them from azure portal. If there is something else wrong then also please let me know .

EDIT :

ERROR - SuspiciousOperation: Attempted access to 'blob url' denied.

user5594493
  • 1,050
  • 3
  • 10
  • 24

1 Answers1

0

Per my experience, the reason for this issue may be that your code does some suspicious access to the on-premises site directory. You could test whether you could get the image URL by running the following code. If you could see the image URL in the console, that indicates you have the access to your azure storage. If not, please let me know.

from azure.storage.blob import BlockBlobService
from azure.storage.blob import PublicAccess 
from azure.storage.blob import ContentSettings

block_blob_service = BlockBlobService(account_name=ACCOUNT_NAME, account_key=ACCOUNT_KEY)
block_blob_service.create_container('newcontainer', public_access=PublicAccess.Container)
block_blob_service.create_blob_from_path(
    'newcontainer',
    'myblockblob',
    'C:\myimages\image.jpg',
    content_settings=ContentSettings(content_type='image/jpg')
            )
image_url = block_blob_service.make_blob_url('newcontainer', "myblockblob")
print(image_url);

You may could find what the problem is by the following URLs.

Django SuspiciousOperation at /upload/ when uploading a file

django suspicious operation on image upload

Hope it helps. Any concerns, please feel free to let me know.

Community
  • 1
  • 1
johnny
  • 319
  • 1
  • 7