pCloud / pcloud-sdk-php

pCloud SDK for PHP
MIT License
54 stars 22 forks source link

Invalid file id using PHP SDK #13

Closed whitsey closed 4 years ago

whitsey commented 4 years ago

Testing uploading and deleting a file

I uploaded a file:

$pcloudFile = new pCloud\File();
$fileName = 'test.pdf';     
$fileMetadata = $pcloudFile->upload($_FILES["attachment"]["tmp_name"], $folderId, $fileName);
return $fileMetadata->metadata->fileid;

Then I passed the fileid to the delete.php and tried to call delete():

$pcloudFile = new pCloud\File();
$fileMetadata = $pcloudFile->delete($_POST["fileid"]);

Result: Fatal error: Uncaught InvalidArgumentException: Invalid file id in pCloud\File.php on line 113 Stack Trace: delete.php:31

Which is this line: $fileMetadata = $pcloudFile->delete($_POST["fileid"]);

I have validated that in delete.php the $_POST["fileid"] is exactly the same as what is returned in upload.php in $fileMetadata->metadata->fileid

It's throwing a Fatal Error and not even a passing an error in the return array.

whitsey commented 4 years ago

My bad. Please delete. After writing I followed the steps and found the problem.

pCloud\File.php:113:

if (!is_int($fileId)) {
    throw new InvalidArgumentException("Invalid file id");
}

I stripped and filtered POST and it is now an int.