1

I try to upload a file to DropBox using their API and PHP. Thats the code:

require_once "dropbox/lib/Dropbox/autoload.php";
use \Dropbox as dbx;
    $appInfo = dbx\AppInfo::loadFromJsonFile("app_info.json");

$csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
$webAuth = new dbx\WebAuth($appInfo, "NoteBoxApp/0.01", "http://localhost/notes", $csrfTokenStore, null);


$title=$_POST["titulo"].".txt";
$nota=$_POST["conteudo"];

$accessToken=$_SESSION["token"];
$clientIdentifier=$_SESSION["userId"];
$client= new dbx\Client($accessToken, $clientIdentifier);

$file = fopen($title, "w") or die("Unable to open file!");
fwrite($file, $nota);
$stat = fstat($file);
$size = (int) $stat['size'];

$dropboxPath="/Aplicativos/Notes01";
try{
    $metadata = $client->uploadFile($dropboxPath, dbx\WriteMode::add(), $file, $size);
}
catch(Exception $e) {
    echo "Exceção: ",  $e->getMessage(), "\n";
}
fclose($file);

I always get the exception

Error executing HTTP request: Operation too slow. Less than 1024 bytes/sec transferred the last 10 seconds

I cant see why! I using XAMPP on localhost!... Thanks in advance for the help!

2 Answers 2

1

I found the solution:

I can't upload a file open in "write" mode!

I have to close the file first then open it again in "read" mode and then it works.

Sign up to request clarification or add additional context in comments.

Comments

0

Are you sure the file you are trying to upload is not empty? It seems that you aren't sending any data at all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.