uploadcare / uploadcare-php

PHP API client that handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.
https://uploadcare.com
101 stars 47 forks source link

deleteFile pitches Guzzle Method Not Allowed error #206

Closed perceptualJonathan closed 1 year ago

perceptualJonathan commented 1 year ago

Describe the bug

I am attempting to delete a previously uploaded file via the Uploadcare API for PHP with a given UUID, but when attempting to do so, there is a Guzzle error blocking the delete. The file was previously uploaded with the PHP API without a problem.

Expected behavior

The file is deleted and the file info of the deleted file is returned

Code / screenshots

Reproducible example to generate the error

require_once 'vendor/autoload.php';
$uuid = "FILEUUID";
$configuration = Uploadcare\Configuration::create($myPublicKey, $mySecretKey);
$apiObj = (new \Uploadcare\Api($configuration));
$apiObjFile = $apiObj->file();
$apiObjFile->deleteFile($uuid);

Error message:

    <b>Fatal error</b>:  Uncaught GuzzleHttp\Exception\ClientException: Client error: "DELETE https://api.uploadcare.com/files/FILEUUID/" resulted in a "405 Method Not Allowed" response:
    {&quot;detail&quot;:&quot;Method \&quot;DELETE\&quot; not allowed.&quot;}
    in /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
    Stack trace:
    #0 /var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(72): GuzzleHttp\Exception\RequestException::create()
    #1 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(209): GuzzleHttp\Middleware::GuzzleHttp\{closure}()
    #2 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(158): GuzzleHttp\Promise\Promise::callHandler()
    #3 /var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
    #4 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Promise\TaskQueue-&gt;run()
    #5 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise-&gt;invokeWaitFn()
    #6 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise-&gt;waitIfPending()
    #7 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise-&gt;invokeWaitList()
    #8 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise-&gt;waitIfPending()
    #9 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Promise\Promise-&gt;wait()
    #10 /var/www/html/vendor/uploadcare/uploadcare-php/src/Apis/AbstractApi.php(92): GuzzleHttp\Client-&gt;request()
    #11 /var/www/html/vendor/uploadcare/uploadcare-php/src/Apis/FileApi.php(124): Uploadcare\Apis\AbstractApi-&gt;request()
    #12 /var/www/html/uploadCareTrial.php(40): Uploadcare\Apis\FileApi-&gt;deleteFile()
    #13 {main}

Environment

optlsnd commented 1 year ago

It seems to be a bug in v4.0.0 https://github.com/uploadcare/uploadcare-php/blob/v4.0.0/src/Apis/FileApi.php#L124. The deleteFile method makes a request to the wrong endpoint. Upgrading to v4.1.* should help.

perceptualJonathan commented 1 year ago

Yes, that was sufficient to fix the issue.