cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Tell us what you want to see on the Community here!
Close

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PHP Codeigniter - Upload file to Dropbox via HTTPS always empty

Highlighted

PHP Codeigniter - Upload file to Dropbox via HTTPS always empty

New member | Level 2

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

1 Reply 1
Highlighted

Re: PHP Codeigniter - Upload file to Dropbox via HTTPS always empty

Dropboxer

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

 

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.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?