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();
        xhttp.open("PUT","https://sofyvhdfiles.file.core.windows.net/sofyvhd/test.txt",false);
        xhttp.setRequestHeader("Authentication", "SharedKey myaccount:[Key Here]");
        xhttp.setRequestHeader("x-ms-version","2017-04-17");
        xhttp.setRequestHeader("x-ms-content-length",102400);
        xhttp.setRequestHeader("x-ms-type","text/plain; charset=UTF-8");
        xhttp.send();
        var response = JSON.parse(xhttp.responseText);
        console.log(response);
    }

    sendFile();

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


Update:

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 https://sofyvhdfiles.file.core.windows.net/sofyvhd/test.txt + SAS token using HTTPS PUT with x-ms-type and x-ms-content-length: