cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We love to hear how every person gets the most from Dropbox, and it seems everyone has a slightly different use for it - tell us yours 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: 

Issue in getting content of PDF/Doc etc

Issue in getting content of PDF/Doc etc

anandjpr
Explorer | Level 3

We are consuming dropbox api from our Delphi App.

We are facing issue in getting PDF from dropbox(Upload,delete is working fine).

anandjpr_0-1625158442022.png

 

Getting Blank PDF

 

Except text file i am facing issue in getting file content(png,Doc,Pdf)
please suggest what wrong is happening there.

 

1 Accepted Solution

Accepted Solutions

Re: Issue in getting content of PDF/Doc etc

Greg-DB
Dropboxer

Thanks! That does show the raw PDF data, indicating that the Dropbox API call itself did succeed and return the file data.

 

That being the case, it looks like the issue here is with writing that data to the local filesystem. As that's not related to the Dropbox API itself, I'm afraid I can't offer much help with that. You'll need to debug that part of your code, such as the "SaveToFile" method. For instance, make sure you have the right local path and that you have the permissions needed to write to that path.

View solution in original post

10 Replies 10

Re: Issue in getting content of PDF/Doc etc

Greg-DB
Dropboxer

First, can you confirm that the "/test/BackcardHTTPS.pdf" file on Dropbox itself is not empty and does contain the expected data?

 

Then, can you inspect the API response? Check the status code; if it's not 200, then the call failed for some reason. You should also check the response headers for metadata, and response body for the file data, if the call succeeded. If it failed, there should be some error.

 

By the way, you shouldn't post your access token like that. You should redact it from your image, and then revoke and replace it.

Re: Issue in getting content of PDF/Doc etc

anandjpr
Explorer | Level 3

I have checked  "BackcardHTTPS.pdf" contain proper data.

And Api response is code is 200.

 

When I am trying to read text file(*.txt) every thing is working fine.

Re: Issue in getting content of PDF/Doc etc

Greg-DB
Dropboxer

What about the rest of the response? What's in the headers and body?

Re: Issue in getting content of PDF/Doc etc

anandjpr
Explorer | Level 3

Request Endpoint:

 https://content.dropboxapi.com/2/files/download

Request header: 

 Authorization  : Bearer <REDACTED>

 Dropbox-API-Arg : {"path":"/test/BankcardHTTPS.pdf"}

 

Please suggest why i am getting Blank PDF file. 

Re: Issue in getting content of PDF/Doc etc

anandjpr
Explorer | Level 3

I am Sharing Sample Project code .

 

Request you to please have a look and suggest what wrong happening there.

 

Sample Code:

procedure TForm6.FormCreate(Sender: TObject);
var
url:string;
lParams: TStream;
FStream: TStream;
SaveDir,TempFile:AnsiString;
MyText: TStringlist;
req:string;
response:AnsiString;
Base64: string;

Input: TStringStream;
Output: TFileStream;

begin
try
FStream := TStringStream.Create;
MyText:= TStringlist.create();
try

IdHTTP1.Request.CustomHeaders.Values['Dropbox-API-Arg'] :='{"path":"/test/BankcardHTTPS.pdf"}';
IdHTTP1.Request.CustomHeaders.Values['Authorization'] := 'Bearer <REDACTED>';
response:=IdHTTP1.Post('https://content.dropboxapi.com/2/files/download',FStream);

MyText.Add(response);
MyText.SaveToFile('.\BankcardHTTPS.pdf');

except
on E: Exception do
begin
ShowMessage('Error: ' + E.Message);
end;
end;
finally
lParams.Free;
MyText.Free;
end;
end;

Re: Issue in getting content of PDF/Doc etc

anandjpr
Explorer | Level 3

Any Update.

Re: Issue in getting content of PDF/Doc etc

Greg-DB
Dropboxer

This shows your request headers and code, but not the response headers or body. Can you inspect the response headers/body?

 

Also, do not post your access token, since it enables access to your account. You should revoke it since you've posted it publicly.

Re: Issue in getting content of PDF/Doc etc

anandjpr
Explorer | Level 3

Sorry i missed to share response in last chat.

I have saved response in txt fine and sharing screenshot with you.

 

anandjpr_1-1625237270274.png

 

 

Re: Issue in getting content of PDF/Doc etc

Greg-DB
Dropboxer

Thanks! That does show the raw PDF data, indicating that the Dropbox API call itself did succeed and return the file data.

 

That being the case, it looks like the issue here is with writing that data to the local filesystem. As that's not related to the Dropbox API itself, I'm afraid I can't offer much help with that. You'll need to debug that part of your code, such as the "SaveToFile" method. For instance, make sure you have the right local path and that you have the permissions needed to write to that path.

View solution in original post

Who's talking

Top contributors to this post

  • User avatar
    anandjpr Explorer | Level 3
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?