Problem with Guzzle Client unable to keep same session

149 views Asked by At

I am currently developing a library to call the pCloud API.

So far I've been able to do what I wanted to do, but I happen to have a problem with the http client (Guzzle, Curl).

I would like to use the "fileops" methods to download a file by chunk. So far all is ok, they provide, it is method in the doc (https://docs.pcloud.com/methods/fileops/).

I can use the methods in Postman without problems, in the browser too. That is, I get my token, then use the "file_open" method to get the file descriptor, then read a part of my file with file_pread.

But doing exactly the same thing on PHP side with Guzzle, Http Client from Symfony, or from pCloud SDK provided by pCloud (https://github.com/pCloud/pcloud-sdk-php) it doesn't work.

It reports that the file remains open as long as you stay on the same session (linked to api token), otherwise it is closed. I have a single client for all requests. "A descriptor is only valid for the same connection. If a connection closes, all the files are also closed. You can open the same file in multiple connections." from doc

What I do in PHP (not working):

// Create instance and login client
$p = new PCloudService($_ENV['PCLOUD_EMAIL'], $_ENV['PCLOUD_PASSWORD']);
// Open file and return fd
$fileOpen = $p->fileOperationOpen((new FileOpenWithFileIdInput(12426385087, PCloudFileOperation::WRITE)));
dump($p->getUserInfo()->getAuth(), $fileOpen);
// Attemp to read 100 first bytes of file
$fileRead = $p->fileOperationRead((new FilePReadWithFileIdInput($fileOpen, 100, 0)));
// API Throw an error code "1007: Invalid or closed file descriptor."

What I do in my browser/postman (working) :

Retrieving the token with (OK) :
http://eapi.pcloud.com/[email protected]&password=xxxxx&getauth=1
Result : Return the user info with the token

Retrieve the file descriptor with (OK) :
http://eapi.pcloud.com/file_open?auth=API_TOKEN&flags=0x0002&fileid=123456
Result : Return JSON with the number "fd" e.g. number : 2

Recover the first 100 bytes of my file with (OK):
http://eapi.pcloud.com/file_pread?auth=API_TOKEN&fd=2&count=100&offset=0
Result : Returns the first 100 bytes of the file.

I try to see what is the difference between Postman and my guzzle browser but I can't find it... (no cookie saved)

Here is the link to the repos: https://github.com/TheoD02/pCloud-API/blob/master/src/Service/PCloudService.php#L153

An answer from them, but does not help more, because no special support for API : If a connection is closed, the files are also closed, this is correct. Opening the same file in several different connections would also create several different sessions. A session has only one token.

The result you get is also correct. You have opened the file (the same file) several times (on several sessions/ because they are different connections). The file descriptor shows the session increment for the file, while the server side gets 1, since it is the same file.

0

There are 0 answers