You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

technocelebes's avatar
technocelebes
New member | Level 2
5 years ago

PHP Codeigniter - Upload file to Dropbox via HTTPS always empty

I'm trying to upload file using Kunnu Dropbox API. It works really well in localhost. But, when I try to upload from live server, it always upload empty file. What am i missing ?

Here is the code to upload :

$pathToLocalFile = base_url() .  "\\public\\dropbox_file\\" . $data['upload_data']['file_name'];$dropBox = $this->load->library("DropBox_lib");$drop_obj = new DropBox_lib();$drop_obj->set_mode_file(1);$drop_obj->set_drop_file($pathToLocalFile);
$drop_n = $drop_obj->drop_object;
$file = $drop_n->simpleUpload($drop_obj->drop_file, $path_f . "/" . $data['upload_data']['file_name'], ['autorename' => true]);

Here is the Library of Dropbox_lib.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

use Kunnu\Dropbox\Dropbox;
use Kunnu\Dropbox\DropboxApp;
use Kunnu\Dropbox\DropboxFile;

class DropBox_lib{
    public $drop_object;
    public $drop_file;
    public $drop_mode;
    
    public function __construct()
    {
        require_once APPPATH.'third_party/DropBox/vendor/autoload.php';

        //Configure Dropbox Application
        $app = new DropboxApp("xxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyy", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");

        //Configure Dropbox service
        $this->drop_object = new Dropbox($app);
    }

    public function set_mode_file($mode){
        if($mode == 1){
            $mode = DropboxFile::MODE_READ;
            $this->drop_mode = $mode;
        }else{
            $mode = DropboxFile::MODE_READ;
            $this->drop_mode = $mode;
        }
    }

    public function set_drop_file($pathlocal){
        $dropboxFile = new DropboxFile($pathlocal, $this->drop_mode);
        $this->drop_file = $dropboxFile;
    }
}

?>

The same codes work really well on localhost.

 

I think the problem is http request with SSL. Because my localhost is using http, while the live server using https

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    [Cross-linking for reference: https://stackoverflow.com/questions/62998138/php-codeigniter-upload-file-to-dropbox-via-https-always-empty ]

     

    We can't provide support for that library itself, as it's not made by Dropbox. That said, it is possible to upload an empty file via the Dropbox API, so it sounds like this code isn't successfully retrieving the local file data to upload when running on your server, and so is issuing the upload API call to the API without any actual file data, resulting in the empty uploaded file.

     

    It looks like you're specifying the local file via the '$pathToLocalFile' parameter, so to troubleshoot this you should make sure that that value is what you expect, and that the path refers to the right file locally on the server, and that your code has the ability to access that path.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,917 PostsLatest Activity: 11 days ago
334 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!