none
SAS Locator/Upload URL Timeout RRS feed

  • Question

  • Hello,

    I am using the Microsft Azure Storage REST API to create a tool to upload files from our Server to our Azure Media Services account, I have been working off this guide: "Upload files into a Media Services account using REST"

    I have all the steps working in a php application except for the last, "Upload a file to blob storage using the upload URL".  When trying to do a "PUT" request to upload the file I receive a timeout exception. I was able to get the upload working through postman and have replicated the headers/body used for that request but still am receiving the timeout.    

    Also, when uploading from the server I would assume the file location should be referenced by the domain i.e. yourdomain.com/uploads/05/08/under10secondvideo.mp4 as opposed to /home/public_html/uploads/05/08/under10secondvideo.mp4 ... Is this correct logic?

    Please advise.

    Wednesday, May 8, 2019 3:30 PM

Answers

All replies

  • Please check the expirytime that you are setting in the request to list the SAS URLs

    https://docs.microsoft.com/en-us/rest/api/media/assets/listcontainersas

    Name Type Description
    expiryTime
    • string

    The SAS URL expiration time. This must be less than 24 hours from the current time.

    permissions

    The permissions to set on the SAS URL.

    In the request body, set the expiry time to a time less than 24 hours from UTC DateTime.Now()

    {
      "permissions": "ReadWrite",
      "expiryTime": "2019-05-08T18:00:00Z"
    }

    Wednesday, May 8, 2019 5:39 PM
  • No it's simpler - you are only allowed to create a Write SAS within a 24 hour window. 

    Your expiry is set to the year "3920", which is just slightly outside of the max 24-hour window allowed

    Try something closer to my example.  Right now it is 2019-05-08T20:31:00Z, so anything between that and 2019-05-00T20:30:00Z should be valid.

    Wednesday, May 8, 2019 8:32 PM
  • UPDATE

    I've managed to get the first ~100 bytes to upload using "src":"/path/to/file.mp4" by setting a false content-length but specifying the content length as anything larger results in a timeout, is there a limit to filesize or recommended way to upload file data in chunks?

    Thanks!

    Wednesday, May 8, 2019 8:48 PM
  • Can you share the code that you are using to upload the file?  Have you already looked at the Storage API for examples on uploading a file to a SAS URL? 

    Sorry, I'm not a PHP user, but there are some examples of using the PHP SDK for Azure Storage to upload to a SAS URL over here on Stack that may help you. We dont have a lot of PHP samples, as we don't get any asks for PHP really. 

    https://stackoverflow.com/questions/39241302/how-can-i-upload-the-blob-in-azure-using-the-shared-access-signature-using-php

    You can  also test your SAS URL quickly to confirm it is good by using the Azure CLI and the Storage commands. 
    see the bottom of this article for a sample script that is helpful. https://docs.microsoft.com/en-us/azure/media-services/latest/cli-create-asset#cli-shell

    There is a commented out section in that article which shows how to upload using a SAS URL. Note that you only need the sas-token portion of the URL 
    # az storage blob upload \ # -c asset-84045780-a71c-4511-801b-711b1a2e76b2 \ # -f C:\Videos\ignite-short.mp4 \ # -n ignite-short.mp4 \ # --account-name mconverticlitest0003 \ # --sas-token "?sv=2015-07-08&sr=c&sig=BvMXDCOjR%2FOP2%2FYi6lVknC4Gcq7fIun5tst8jgED7zY%3D&se=2018-04-25T00:00:00Z&sp=rwl" \


    Wednesday, May 8, 2019 10:15 PM
  • @John Deutscher

    I took both of your suggestions John, reducing access policy duration to 23 hours, and AjayKumar, sending file content, and I managed to get this working.  For anyone stumbling on this thread with a similar issue the code I used is below.  The issue was in how I was sending the file to Azure, you need to set the post field as the actual file content retrieved from file_get_contents(/path/to/file.mp4).  

        $file_path = '/path/to/file/on/server.mp4';
        $file_content = file_get_contents($file_path);
        $content_length = strlen($file_content);
        $header = [
          'x-ms-blob-type:BlockBlob',
          'Content-Length: '.$content_length
        ];
    
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL , $sas_url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_HEADER , 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER , 1);
        curl_setopt($curl, CURLOPT_TIMEOUT, 120);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $file_content);
    
    
        $response = curl_exec($curl);
        $err = curl_error($curl);
    
        curl_close($curl);
    
        if ($err) {
          echo "cURL Error #:" . $err;
        } else {
          echo $response;
        }
    

    Thursday, May 9, 2019 3:05 PM
  • Glad to know that the issue is sorted out. Thank you for sharing the solution that worked for you, it would benefit community members with a similar issue.

    Thursday, May 9, 2019 5:54 PM
    Moderator