How to delete a file from azure storage in PHP

Hi @tilal.ahmad,

Thank you so much for all of your quick responses.
What if I want to delete the converted file after I have downloaded it locally, so we can free up space.
How can we do that? How can we delete a file from Storage using PHP?
This post says we can’t do that
https://forum.groupdocs.com/t/how-to-delete-an-uploaded-file/2570

Regards,
Gopal

I think, I found the code

  $storageApi = new GroupDocs\Storage\Api\StorageApi($configuration); 

  try 
  {
  	$path = "one-page.docx";
	$versionId = null;
	$storage = "MyStorage";
	$request = new Requests\DeleteFileRequest($path, $versionId, $storage);
	$response = $storageApi->deleteFile($request);

	echo "File Deleted.";
	echo "<br>";
  } 
  catch (Exception $e) 
  {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
  }

I’ll update, whether it worked or not.

Thank you
Gopal

@gopalsharma

Please note GroupDocs.Viewer Cloud API has its API methods to work with storage. Please check the sample PHP code to delete a file from storage. Hopefully, it will help you to accomplish the task.

Delete a file from Cloud Storage

1 Like

@tilal.ahmad
yes, it worked.
Just for the information for others facing a similar issue
Method name is deleteFileRequest() d being in smaller case and it’s parameter are $path, $storage, $versionId and not $path, $versionId, $storage.
$storage being the 2nd and $versionid being the 3rd parameter.

The coorect ways is as followes
$request = new Requests\deleteFileRequest($path, $storage, $versionId);

Thank you,
Gopal

1 Like