Getting broken images from blob storage in Azure w

2019-08-08 17:40发布

My php code seems correct, (the part that talks to blob storage).

        //talk to blob storage, get links, based on file name

                $storageClient = $this->azure->get_blob_storage();

foreach($result as $photo)
{
$sharedAccessUrl[] = $storageClient->generateSharedAccessUrl(
               'container',
              $photo['File'],
               'b', 
               'r',
               $storageClient ->isoDate(time()),
               $storageClient ->isoDate(time() + 3000)
              );


}

      foreach($sharedAccessUrl as $item)
      {
     $pictures[] = $item;
      }

This gets all the absolute url links, I then store it inside an array, pass it to the view and retrieve the images. Like this:

<img src="<?php echo $pictures[$i]; ?>" height=100px width="100px">

(where pictures[$i] = http://azure blobstorage etc...

On my local machine, everytime I refresh the page, or flick through pages where there are images, they all load up fine. However, when I upload my app onto azure web-sites, often I get broken images, and will then need to "refresh the page" every time it happens for the image to appear. This is despite the link to the image being correct, after I click on inspect element on the div where the image is suppose to appear.

I am using "shared version" of azure web sites from the 3 month trial. PHP version is exactly the same as my local machine, along with the .net framework.

Does anyone have any idea why this is happening?

I have checked the logs but they are not helpful.

Solution:

There seems to be a delay with the times set at blob storage and azure web sites.

           $storageClient ->isoDate(time()-60),
           $storageClient ->isoDate(time() + 3000)

add -60 to the first line. And it should work.

1条回答
手持菜刀,她持情操
2楼-- · 2019-08-08 18:05

Looks like you answered your own question. It's not so much delay as it is clock-drift and time synchronization between compute nodes and storage nodes. It's always a good idea to set the start time to a minute or two prior to when you want the link to begin working (assuming you intend for the link to work "right now"). No harm start-time going back-in-time.

查看更多
登录 后发表回答