cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to make sure we keep you updated on the ideas that other users have shared here on the Community? Us too! Check them out over here.

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: 
1
Ask
2
Comments

Re: We need Long-live access token

Re: We need Long-live access token

Здравко
Super Collaborator | Level 20

@msmoe wrote:

...

size is 0. why sir?


Hi @msmoe,

This means the file has been uploaded incorrectly. Do you able see the same file using the web interface of your account? Is there some content? How have you uploaded it; using web interface, locally installed Dropbox application, or API (in your application)?

Re: We need Long-live access token

msmoe
Helpful | Level 5

Hi @Здравко 

I used dropbox http method in laravel. And The file goes into the app.

The response I got is the same as the response in the Documentation.

In Here

 

Me uploaded Code below!

 

$filename = $request->file('video')->getClientOriginalName();
        if($request->hasFile('video'))
        {
            $args = array(
                "autorename"=> false,
                "mode"=> "overwrite",
                "mute"=> false,
                'path' => '/'.'video'.'/'.$filename,
            );
            $client = new \GuzzleHttp\Client();
            $res = $client->request("POST", "https://content.dropboxapi.com/2/files/upload", [
                'headers' => [
                    'authorization' => "Bearer {$this->getToken()}",
                    'Content-Type'=> 'application/octet-stream',
                    'Dropbox-API-Arg' => json_encode($args)
                ],
                'data-binary'=>$filename,
            ]);

below my app figure

 

drop1.JPG

Its OK,sir.

But 

When I click on the link in the response and download, the resulting file cannot be opened.

And Size is 0 . Why? 

Please explain Sir.

Thank.

 

Re: We need Long-live access token

Здравко
Super Collaborator | Level 20

Hi @msmoe,

Seems you haven't read your tooling documentation. What is:


@msmoe wrote:
...
            $res = $client->request("POST", "https://content.dropboxapi.com/2/files/upload", [
                'headers' => [
                    'authorization' => "Bearer {$this->getToken()}",
                    'Content-Type'=> 'application/octet-stream',
                    'Dropbox-API-Arg' => json_encode($args)
                ],
                'data-binary'=>$filename,
            ]);

...


... this 'data-binary'?! 🤔 Can you point out to the place where this is described? After that, you need to post your file content, not the file name!!! Even if your call would successful, the resulted file's gonna contain only the file name; nothing more. Since the request body is completely empty now, the file is empty too. 🙂 Take a bit more care; rely on check and error only when you don't have any documentation.

Hope this gives direction.

Re: We need Long-live access token

msmoe
Helpful | Level 5

Hi @Здравко 

Thank You Sir.

 

If so, how to do it? Sir. Please Help.

Because I've tried and I can't.

Because it's important to me Sir.

 

Please Help Me Sir.

Re: We need Long-live access token

Здравко
Super Collaborator | Level 20

@msmoe wrote:

...

If so, how to do it? Sir. Please Help.

Because I've tried and I can't.

...


🤔 I'm not sure what actually you ask me. Do you ask me how you can do a post HTTP request? 🧐 If so, you have already done one successful - take a look on your call to /2/files/get_temporary_link (the result of which is last post of you on previous page). There you have posted calls parameters in the body. That's exactly what you need to do here - post in the same body, but the file content instead of the parameters. The parameters (for such a call - upload call) are passed as 'Dropbox-API-Arg' header (something you have done properly). 😉 That's it - exactly how explained in the call description.

If I have something misinterpreted in your question, clarify what you mean more precisely.

Re: We need Long-live access token

msmoe
Helpful | Level 5

Hi @Здравко 

Thank You for reply.
Please help me Sir.
When uploading succeeded, But in the dropbox app the file size is 0 why?
As Sir said The requested file is the body.
It is shown below. Where is it wrong?
And Sir said above Is it because data-binary is wrong?

Please help me Sir.

I hope it will help you sir.

 

If possible, could you show me the code as an example?

I used php/laravel Sir.
I'm a junior so it's hard to explain in writing.

 

drop2.JPG

 

Thank Sir.

 

Re: We need Long-live access token

Greg-DB
Dropboxer

@msmoe I see that the file you have uploaded has a size of 0 bytes, meaning it doesn't contain any data. When uploading files, you'll need to make sure you send the data you want uploaded for that file.

 

For instance, if you're using /2/files/upload, you'll need to send the file data in HTTPS request body, as that endpoint is a "content-upload" style endpoint. You should refer to the documentation for whatever HTTPS client you're using to perform that call for information on how to supply the file data in the request body. (Note that "data-binary" is the name of a parameter used by "curl" on the command line, but that may not necessarily also be the name of the parameter you should be using for your HTTPS client.)

Re: We need Long-live access token

msmoe
Helpful | Level 5

Hi @Greg-DB 

Thank You for reply.

Sir, I don't understand what you are saying.

I am refer to the documentation.

 

My Code is below Sir.

Where is it wrong?  And Where is it needed?

Please help me Sir.

Because I've tried and I can't.

Because it's important to me Sir.

Please

 

$filename = $request->file('video')->getClientOriginalName();
        if($request->hasFile('video'))
        {
            $args = array(
                "autorename"=> false,
                "mode"=> "overwrite",
                "mute"=> false,
                'path' => '/'.'video'.'/'.$filename,
            );
            $client = new \GuzzleHttp\Client();
            $res = $client->request("POST""https://content.dropboxapi.com/2/files/upload", [
                'headers' => [
                    'authorization' => "Bearer {$this->getToken()}",
                    'Content-Type'=> 'application/octet-stream',
                    'Dropbox-API-Arg' => json_encode($args)
                ],
            ]);

 

Re: We need Long-live access token

Здравко
Super Collaborator | Level 20

@Здравко  wrote:

... this 'data-binary'?! 🤔 Can you point out to the place where this is described? ...



@msmoe wrote:

...

I am refer to the documentation.

...


Hmm... really... Where is this documentation? Read it and probably you won't need somebody to tell you what you have to do. Again your main issue is the empty request body - leading to empty file (not only wrong parameter)! Where are you filling the request body in your code? As Greg correctly told you 'data-binary' is command line curl parameter. What is the equivalent parameter in your environment?

 

For easier debugging redirect the request to http://httpbin.org/post and upload some text file for easier reading (instead of binary one - like media file). Dump the result and see what you are sending actually, including the request body. Is it correct? Read the "big books" and try correct the request until correct one (matching to /2/files/upload).

 

One thing you can do is to create a text file with content something like "My body is Hello World" and name "test.txt". Next make a post request like:

curl -X POST http://httpbin.org/post \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'Dropbox-API-Arg: {"autorename":false,"mode":"overwrite","mute":false,"path":"/video/test.txt"}' \
  -H 'Content-Type: application/octet-stream' \
  --data-binary @test.txt

 As a response you will get description of what you have sent. It's easy to see what you have sent as a body (the file content). After that, replace the URL in your code and see what's there. While reading your documentation, try to make your request in code to be similar to what curl does (least the body, labeled as "data", has to be the same).

Good luck.

Re: We need Long-live access token

Greg-DB
Dropboxer

@msmoe In the latest code snippet you shared, I don't see where you're attempting to set the request body to contain the file data to upload, so you would get an empty file uploaded.

 

I see you're using "GuzzleHttp" as your network client. That's not made by Dropbox, so I can't offer help with that, but it looks like the documentation can be found here.

Need more support?