how to limit azure blob upload size via SAS

Alex King 20 Reputation points
2024-05-14T05:37:22.95+00:00

I'm working on a website that allow users to upload files. I want file size limit below 100mb. When i'm signing SAS, I didn't find any param or option about it. Nobody want the bad guy upload a 100TB file and destory my website. So, how can I do that?

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,192 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sebastian Pokuciński 75 Reputation points
    2025-05-13T12:02:26.7033333+00:00

    @Sumarigo-MSFT
    It's been a year - do we have this feature available?

    As far as I understand the proposed solutions, they are simply not acceptable. You expect the app creator to deal with heavy internet traffic and waste resources on processing unacceptable requests. In the era of bots and automated API attacks this is an urgent issue to be fixed.


2 additional answers

Sort by: Most helpful
  1. TP 124.7K Reputation points Volunteer Moderator
    2024-05-14T06:20:05.8033333+00:00

    Hi Alex,

    There is no built-in method to limit the blob size that a user with valid SAS can upload.

    Instead of allowing a user to upload a file directly to azure storage, what I would recommend is to have them upload to your application, your application enforces the limit, and then your application uploads the file to storage if it is below limit. In this way you are preventing rogue user from costing you large amount of money.

    Please click Accept Answer and upvote if the above was helpful.

    Thanks.

    -TP


  2. Sumarigo-MSFT 47,466 Reputation points Microsoft Employee Moderator
    2024-05-14T09:54:15.1866667+00:00

    @Alex King Welcome to Microsoft Q&A Forum, thank you for posting your query here!

    To limit the file size during an upload to Azure Blob Storage using a Shared Access Signature (SAS), you can’t directly specify the file size limit in the SAS itself. However, you can enforce the limit by implementing a check in your application logic before generating the SAS.

    For instance, you could use Azure Functions or another server-side logic to check the file size before providing the SAS to the user for upload. If the file exceeds the specified size limit, the SAS would not be generated, and the upload would not proceed.

    Additionally, you can look into Azure Blob Storage’s event-driven architecture with Azure Event Grid, which can react to blob creation events. You could create a subscription to these events and trigger a function to check the file size after the upload. If the file size exceeds the limit, you can then take appropriate actions, such as deleting the file.

    Remember to also consider the maximum file size limits that Azure Blob Storage supports for different blob types when designing your solution.

    Additional information: https://learn.microsoft.com/en-us/answers/questions/891323/how-to-increase-file-upload-capacity-over-100mb

    And Azure Blob Storage Limits: https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/azure-subscription-service-limits#azure-blob-storage-limits

    Please let us know if you have any further queries. I’m happy to assist you further.    


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.