question

rodolfotuble-4323 avatar image
0 Votes"
rodolfotuble-4323 asked ·

how to copy a locally created file to azure file storage using PHP

I'm trying to follow this link: https://docs.microsoft.com/en-us/rest/api/storageservices/copy-file with examples from this repo: https://github.com/Azure/azure-storage-php/blob/master/samples/FileSamples.php#L235 The file is indeed copied to the azure server but the content aren't readable, to say the least, it takes a size but it's empty. This is only a text file as well, and what I plan to achieve after fixing this is to copy excel files generated via PHP to an azure file storage server.

azure-webapps
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Grmacjon-MSFT avatar image
0 Votes"
Grmacjon-MSFT answered ·

Hi @rodolfotuble-4323,


Are you getting any error messages or confirmation message that the file has been copied to the Azure server? When you say "not readable " what does that mean? you should get a 202 status code if the copy was successful.


A few things to keep in mind:


-If the destination file exists, it will be overwritten. The destination file cannot be modified while the copy operation is in progress.


-The Copy File operation always copies the entire source blob or file; copying a range of bytes or set of blocks is not supported


-The destination file is always the same size as the source blob or file, so the value of the Content-Length header for the destination file matches that for the source blob or file.


Hope that helps.


-Grace


· 2 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

 I forgot to mention that we are using file.core not blob.core.

       I think what's happening is that my code is just creating the file and not copying it since the file in the azure storage only has this content. see attached

      Also, I for some reason I can't post my code in the question so I'll try and paste it in here.

9432-azure.jpg



0 Votes 0 · ·
azure.jpg (18.7 KiB)
      $sourcePath = sprintf(
         '%s%s/%s',
         (string)$fileClient->getPsrPrimaryUri(),
         $shareName,
         $srcfileName
     );
    
     try {
         // Create destination file.
         $fileClient->createFile($shareName, $dstfileName, 1024);
         // Copy file.
         return $fileClient->copyFile($shareName, $dstfileName, $sourcePath);
     } catch (ServiceException $e) {
         $code = $e->getCode();
         $error_message = $e->getMessage();
         echo $code . ": " . $error_message . PHP_EOL;
     }
0 Votes 0 · ·