Dropbox icon indicating copy to clipboard operation
Dropbox copied to clipboard

Expecting a file upload (Status Code: 400)

Open Blacx opened this issue 12 years ago • 17 comments

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: Expecting a file upload

Blacx avatar Jan 11 '13 15:01 Blacx

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?

BenExile avatar Jan 11 '13 17:01 BenExile

@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.

henrylevak avatar Jan 11 '13 18:01 henrylevak

@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.

Blacx avatar Jan 11 '13 18:01 Blacx

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.

BenExile avatar Jan 11 '13 22:01 BenExile

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 :(

henrylevak avatar Jan 12 '13 19:01 henrylevak

No problem! @Blacx - Can you advise if this problem occurs for all uploads or just some of them?

BenExile avatar Jan 12 '13 19:01 BenExile

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...

henrylevak avatar Jan 13 '13 06:01 henrylevak

Same for me @henrylevak. I'll need to get a 5.3.1 install up and running to see if I can replicate.

BenExile avatar Jan 13 '13 10:01 BenExile

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.

Blacx avatar Jan 13 '13 10:01 Blacx

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?

BenExile avatar Jan 14 '13 19:01 BenExile

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.

Blacx avatar Jan 15 '13 03:01 Blacx

Hi @Blacx,

Unfortunately I'm still unable to replicate this. Do you have any more information about what might be causing the issue?

BenExile avatar Feb 01 '13 14:02 BenExile

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.

Blacx avatar Feb 04 '13 06:02 Blacx

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.

BenExile avatar Feb 04 '13 20:02 BenExile

I was running php 5.6.2

applemate avatar Apr 08 '15 05:04 applemate

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.

abusohib avatar Jul 20 '15 05:07 abusohib

not work. Expecting a file upload ...

reimax avatar Mar 29 '16 20:03 reimax