jakeFeldman / strapi-provider-upload-azure-storage

Strapi Provider Upload Azure Storage
MIT License
75 stars 42 forks source link

Fix URL issue in the plugin #83

Closed bs2603 closed 11 months ago

bs2603 commented 11 months ago

Hi,

I have a strapi and next.js (frontend) based website. I recently migrated its data to an azure container, and came across this issue.

Issue

When uploading an image to the strapi admin dashboard, the image would get uploaded to azure, but the thumbnail wasn't visible for preview

Image_upload_issue

Right click, open image in new tab showed BlobNotFound error -

<Error>
<Code>BlobNotFound</Code>
<Message>The specified blob does not exist. RequestId:--- Time:--- </Message>
</Error>

Page URL - my_azure_account/data/brands/thumbnail_image_optimization_c467bd6cd4.webp?width=900&height=600

Please note that the image was getting uploaded correctly to the container, only the preview wasn't available.

Reason

The reason behind this error was that the plugin was adding Container Name to the generated URL. While the actual image was getting uploaded to the same URL, without the container name in it.

Page URL - my_azure_account/data/brands/thumbnail_image_optimization_c467bd6cd4.webp?width=900&height=600

Image correctly uploaded at - my_azure_account/brands/thumbnail_image_optimization_c467bd6cd4.webp?width=900&height=600

Solution

Due to other team regulations, I cannot change settings on my azure portal. I believe there would be other users who would encounter a similar problem in the future. Thus I have added an optional check.

  1. In the configuration I have added a new optional parameter removeCN which can be set to true.
  2. Updated thehandleUpload function to check whether the parameter exists and is true, and simply removes the substring with container name -
    if (file.url.includes('/'+config.containerName+'/') && config.removeCN && config.removeCN=='true') {
        file.url = file.url.replace('/'+config.containerName+'/', '/');
    }

I have compiled the code on my local system and checked it, it works correctly with no errors.I have tried to maintain continuity and readability in the code, let me know if there is any issue.

Regards, Bhavya bhavyas2603@gmail.com

bs2603 commented 11 months ago

Hi,

I've added the changes you suggested and have run yarn lint --format. Let me know if there's anything else needed.

Thank you for your guidance!

jakeFeldman commented 11 months ago

Thanks again for the PR. I've published version 3.3.0 and this should be available on npm now.

bs2603 commented 11 months ago

Thank you!