PHP Classes

Bug: Missing $response under certain file upload conditions

Recommend this page to a friend!

      PHP OAuth Library  >  PHP OAuth Library package blog  >  How to Implement a PH...  >  All threads  >  Bug: Missing $response under certain...  >  (Un) Subscribe thread alerts  
Subject:Bug: Missing $response under certain...
Summary:The API $response is missing when uploading files
Messages:3
Author:Meitar
Date:2016-01-23 06:46:39
 

  1. Bug: Missing $response under certain...   Reply   Report abuse  
Picture of Meitar Meitar - 2016-01-23 06:46:39
Hi,

As a follow up to my last post (http://www.phpclasses.org/discuss/package/7700/thread/329/) I have noticed that the last parameter to CallAPI(), which is supposed to be the response of the request, is missing when trying to upload files.

This seems to happen because of lines 1684 and 1685 which check for an error from the HTTP client library:

---- BEGIN CODE SNIPPET ----

if(strlen($error = $http->SendRequest($arguments))
|| strlen($error = $http->ReadReplyHeaders($headers)))
{
$http->Close();
return($this->SetError('it was not possible to retrieve the '.$options['Resource'].': '.$error));
}

---- END CODE SNIPPET ----

If the user doesn't set a "custom" file name when uploading files, then the above part of SendAPIRequest(), returns prematurely, setting an error. However, the docs indicate that a custom file name is not required, so I don't think this should be an error.

Unfortunately, setting a custom file name ALSO doesn't work because then the GetFileDefinition() method inside the HTTP client library gives a different error: "it was not possible to access the file …".

The result is that, when uploading files, it is impossible to read the API call's result.

  2. Re: Bug: Missing $response under certain...   Reply   Report abuse  
Picture of Meitar Meitar - 2016-01-23 06:54:37 - In reply to message 1 from Meitar
Okay, the simple (and possibly dangerous) fix for this, at least for me, was to insert the following code in http.php at line 810:

---- BEGIN CODE ----

if(IsSet($file["FileName"]) && is_array($file["FileName"]))
$file["FileName"]=$file["FileName"][0];

---- END CODE ----

This fixes the issue for me. The issue seems to be caused because the OAuth library asks for its Files to be arrays, but the http library doesn't handle them if they are arrays.

I can make a diff of this if you like. I cannot guarantee the safety of this change, since…um…I do not know how or if these libraries are unit tested.

  3. Re: Bug: Missing $response under certain...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-01-23 20:56:50 - In reply to message 1 from Meitar
I just tried the Twitter example of submitting a tweet with attached media without a file name and it works.

Can you provide a more complete example code that does not work for you?