0

I want to output a file from Dropbox onto my website with Dropbox PHP Core SDK. To give an example, I upload an image to Dropbox. Now, how do I display that image to my website from Dropbox's servers. Keep in mind, I don't want to download this file from Dropbox and then display that image. Is it possible to display an image or another file directly from Dropbox using Dropbox PHP Core SDK?

EDIT:Would you mind being more clear on #1

How do I use the custom URL?

Can I do this: header("location: $url);

Is this how you use the custom url? Thanks!

1 Answer 1

0

Using the PHP Core SDK, the main way of accessing file content is using the getFile method, or for images where you don't need the full resolution, the getThumbnail method. However, these return the data directly, e.g., to save on your server and serve back to the user, so that doesn't suit your needs as described.

It sounds like you'd prefer the API to return a link to the image that you can use as the source for the images in the HTML of your page. The Dropbox API doesn't offer a method particularly well suited for that, but there are some non-ideal options:

1) You can use createTemporaryDirectLink to get a direct URL to the image. Note that these links expire after four hours though.

Using it would look like:

list($url, $expires) = $client->createTemporaryDirectLink("/default.png");

2) You can use createShareableLink to get a preview URL for the image. These links don't expire. Note that these don't link directly to the image data though, so you'd need to modify them as documented in this help article.

Using it would look like:

$url = $client->createShareableLink("/default.png");

Also, not that both of these are subject to bandwidth restrictions, per this help article.

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

2 Comments

#1 looks like the best example. Would you mind giving an example with something like default.png?
I added some sample code showing how you might call these methods.

Your Answer

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