Search code examples
azureazure-media-services

Azure Media Services Limit File Size


Looking at the Azure Media Service REST API I can't see any way to limit the upload size of a file:

https://learn.microsoft.com/en-us/azure/media-services/media-services-rest-upload-files

For example I want a user to directly upload a file to azure but limit it to 50mb. I don't want to proxy the request via my servers first because that seems like unnecessary bandwidth usage.

Is it possible to do this with Azure? If it isn't possible to do it directly on Azure what is the best way to indirectly restrict the file upload size?


Solution

  • If you don't want to proxy the upload you'll need to use browser-side validation. HTML5's File API has the answer.

    From https://stackoverflow.com/a/4307882/4148708:

    if (typeof FileReader !== "undefined") {
        var size = document.getElementById('myfile').files[0].size;
        // check file size
    }
    

    Of course this doesn't stop the user from using something like Postman to work around the limitation, but i mean, come on,

    nobody got time for that

    If you're more interested in something like the duration of the video rather than raw file size, you absolutely need to proxy the content bytes first – see this thread for more:
    Verify duration of video which has been uploaded into azure blob