FineUploader / fine-uploader

Multiple file upload plugin with image previews, drag and drop, progress bars. S3 and Azure support, image scaling, form support, chunking, resume, pause, and tons of other features.
https://fineuploader.com
MIT License
8.18k stars 1.87k forks source link

Implemented caching for sas response if a validity period is provided… #2039

Open szilardd opened 6 years ago

szilardd commented 6 years ago

Brief description of the changes

Currenly when using the Azure version and activating the 'chunked' option, on every chunk it calls the signature endpoint to retrieve a SAS.

But you can specify an expiry time for the SAS (SharedAccessBlobPolicy.SharedAccessExpiryTime) and based on this, the SAS can be cached by the browser and a new request can be sent only when it expires

For reference this is the C# code that creates the SAS and returns the url and the validity period

// the SAS will be valid for 5 minutes
var validForMinutes = 5;
var blob = new CloudBlockBlob(new Uri(blobUri), credentials);

var policy = new SharedAccessBlobPolicy()
{
    Permissions = SharedAccessBlobPermissions.Write,
    SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(validForMinutes),
};

var sas = blob.GetSharedAccessSignature(policy);

// instead of just returing the SAS url, return also the amount of time the SAS is valid for
return new
{
    sasUrl = blob.Uri + sas,
    validFor = validForMinutes * 60 // seconds
};

What browsers and operating systems have you tested these changes on?

Chrome on Windows so far, but will test across other browsers

Have you written unit tests? If not, explain why.

Looking for a confirmation first that this is something that the maintainers will agree on including. Happy to write tests.