Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Expecting a file upload (Status Code: 400) #67

Open
Blacx opened this issue Jan 11, 2013 · 17 comments
Open

Expecting a file upload (Status Code: 400) #67

Blacx opened this issue Jan 11, 2013 · 17 comments

Comments

@Blacx
Copy link

Blacx commented Jan 11, 2013

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

@BenExile
Copy link
Owner

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?

@henrylevak
Copy link

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

@Blacx
Copy link
Author

Blacx commented Jan 11, 2013

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

@BenExile
Copy link
Owner

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

@henrylevak - Thanks I'll await your reply.

@henrylevak
Copy link

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

@BenExile
Copy link
Owner

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

@henrylevak
Copy link

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

@BenExile
Copy link
Owner

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

@Blacx
Copy link
Author

Blacx commented Jan 13, 2013

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.

@BenExile
Copy link
Owner

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?

@Blacx
Copy link
Author

Blacx commented Jan 15, 2013

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.

@BenExile
Copy link
Owner

BenExile commented Feb 1, 2013

Hi @Blacx,

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

@Blacx
Copy link
Author

Blacx commented Feb 4, 2013

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.

@BenExile
Copy link
Owner

BenExile commented Feb 4, 2013

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.

@applemate
Copy link

I was running php 5.6.2

@abusohib
Copy link

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 79ea42d

It has fixed my problem.

@reimax
Copy link

reimax commented Mar 29, 2016

not work. Expecting a file upload ...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants