How to write a text file from a webserver to an Azure Fileshare?

We currently have a webpage that on submit of a form uses PHP and creates a text file onto a webserver. We want to write this text file to an Azure File Share (not a blob) so we can access it from a VM. How do we go about doing this, we have tried using HTTPS POST requests and have hit a wall with CORS and now we are lost.

    function sendFile(){
        var xhttp = new XMLHttpRequest();"PUT","",false);
        xhttp.setRequestHeader("Authentication", "SharedKey myaccount:[Key Here]");
        xhttp.setRequestHeader("x-ms-type","text/plain; charset=UTF-8");
        var response = JSON.parse(xhttp.responseText);


You can set CORS rules for file storage service using the Azure portal.


Thanks for Gaurav’s reminding in the comment. As you are using Javascript, it’s better to use SAS (Shared Access Signature) to create a file. SAS is much easier and more secure to use than SharedKey in front-end. You can follow the steps below to do that.

  1. Generate SAS from the Azure portal and copy the SAS token:
  1. Call + SAS token using HTTPS PUT with x-ms-type and x-ms-content-length: