Dropbox
Dropbox copied to clipboard
Expecting a file upload (Status Code: 400)
Dear @BenTheDesigner ,
I'm having an error when running putFile.php.
The error message that appears is as follows:
Catchable fatal error: Object of class stdClass could not be converted to string in C:\xampp\htdocs\dropbox\new\Dropbox\OAuth\Consumer\Curl.php on line 103
But I tried to change $response['body']->error
on \Dropbox\OAuth\Consumer\Curl.php file at line 103 be as follows:
$message = $response['body']->error->file . ' (Status Code: ' . $response['code'] . ')';
And the exception that appears now is "Expecting a file upload".
Here is the putFile.php which I modified:
require_once('bootstrap.php'); try { $tmp = tempnam('/tmp', 'dropbox'); $data = 'This file was uploaded using the Dropbox API!'; file_put_contents($tmp, $data); $put = $dropbox->putFile($tmp, 'api_upload_test.txt'); unlink($tmp); var_dump($put); } catch (\Dropbox\Exception $e) { var_dump($e); }
Here is the output:
Hi @Blacx
The fatal error is due to Dropbox returning an object as the error message. I have submitted a ticket to Dropbox as $response['body']->error
, to my knowledge, has always been a string. I'll need to wait for their response before I can reliably fix this issue (it might be a problem on their end).
The Exception thrown suggests no file was uploaded but I have not seen this since the very early days of testing the API and getting cURL to prepare the POST request as required. Is this problem apparent if you use a 'permanent' file that is on your system?
I spent half an hour on my lunch break trying to replicate this issue but no luck so far. @henrylevak (sorry to drag you in) - As you did have the same problem with the previous issue are you able to confirm if this problem also affects you?
@Blacx I'll test it when I get home tonight - I was able to successfully upload files earlier this week - but I'll try it later tonight as well.
@BenTheDesigner : Yes, I am having the same problem when I enter the address of the file directly as a parameter of putFile () method. If it is the intention of 'permanent' you mean Ben.
ex: $put = $dropbox->putFile ('C:\directfile.txt', 'api_upload_test.txt');
@henrylevak : I hope it help me.
I do have confirmation from Dropbox that the API returns error messages inconsistently... Useful! This is being looked at by their team, but I'm told the likelihood is that this behaviour won't be changed in version 1 of the API.
I'm still unable to replicate the error with uploading files but have addressed the code that was triggering the fatal in commit 5bbf95b5b36f4da9d43a52c8c96e9b20d2759368.
@henrylevak - Thanks I'll await your reply.
Sorry to disappoint all but I haven't had any time to check on this. I had to finish a feature last night and ran out of time . I'll try again tonight :(
No problem! @Blacx - Can you advise if this problem occurs for all uploads or just some of them?
So I used @Blacx 's code and had no problems what so ever..
putFile($tmp, 'api_upload_test1.txt'); unlink($tmp); var_dump($put); } catch (\Dropbox\Exception $e) { var_dump($e); } This uploaded the file perfectly...
Same for me @henrylevak. I'll need to get a 5.3.1 install up and running to see if I can replicate.
Hi @BenTheDesigner only putFile.php is problematic for me, the other work normally even putStream.php also work well. I would be very delighted if you intend to try it in version 5.3.1 ben. Thank you very much in advance.
And thank you @henrylevak to try and provide information.
Hi @Blacx
I'm unable to replicate this issue under 5.3.1. It's very strange that this only affects the putFile method, too. Can you advise if the problem persists and if you've found out any more about the issue?
Hi @BenTheDesigner,
I was trying to execute putFile in PHP 5.3.18 and the result goes perfectly. But it's weird and still not be another clue to run it in PHP 5.3.1.
Still trying to solve the problem while waiting for a solution.
Hi @Blacx,
Unfortunately I'm still unable to replicate this. Do you have any more information about what might be causing the issue?
Hi @BenTheDesigner,
I do not have a solution as well. While I still think that the error occurred because of PHP version 5.3.1 that I use.
PHP 5.3.1 does meet the minimum requirement and all code to date is tested under that version. I'll leave this issue open so others can comment if they experience the same issue. Sorry I can't help more on this occasion.
I was running php 5.6.2
I faced same problem. i was running php 5.6.10
I found the answer . There is a new Variable included with curl in PHP 5.5: CURLOPT_SAFE_UPLOAD this is set to false by default in PHP 5.5 and is switched to a default of true in PHP 5.6.
I have set CURLOPT_SAFE_UPLOAD = false in https://github.com/BenExile/Dropbox/commit/79ea42dcc4afd4e21af0597ff0c6e47c2a557e21
It has fixed my problem.
not work. Expecting a file upload ...