2

I am working with Dropbox API using JAVA SDK. I try to get the thumbnail for each image in my dropbox account via API. Honestly, after I read the class and they just provided the description which is not useful enough for the beginner. I begin my code like this

public void getThumbnails() throws DropboxException{

    DropboxInputStream dis = api.getThumbnailStream("/Koala.jpg", ThumbSize.ICON_256x256, ThumbFormat.JPEG);

}

What I don't understand is:

  1. I should return something to client side in order to show the thumbnail I got from DropboxAPI but I don't know what I should return. Maybe DropboxInputStream?
  2. How do I get the thumbnail from API? I try to find the example or guide for a day but I can't find any guide...

please someone guide me how to get the thumbnail via dropbox API

Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68
Takumi
  • 355
  • 1
  • 7
  • 19

2 Answers2

1

DropboxInputStream is just a FilterInputStream so after you get the input stream like you wrote you can just iterate the input stream and read it.

Then it's only a question of the way you need to present it. Is it a Swing application you are writing? how do you need to show that image?

arikg
  • 402
  • 2
  • 4
  • 17
  • I need to show the image on webpage. Normally dropbox API has 2 methods, getThumbnail and getThumbnailStream. I don't know what is the different of them but I guess I can use getThumbnailStream to show it...Am I wrong??? – Takumi Sep 25 '12 at 09:11
  • They are basically different ways of doing a similar thing. if you want the actual image then `getThumbnailStream` is a good option but it still only gets you the actual file data bytes. Now you need to either save it or return it to the web page. This is now a separate issue unrelated to dropbox in any way. – arikg Sep 25 '12 at 09:20
  • This is a much broader question but you basically have two options, either save the image to disc and return it to the user using some resource servlet or return it right in this request as an image response. it depends much more on where your code is located. If this is a general "getData" callk then you need to save it. If it's a "getImageX" call then you need to return this image to the browser. – arikg Sep 25 '12 at 09:22
  • To really know how this is handled we need to be familiar with the entire context of the call... – arikg Sep 25 '12 at 09:24
  • So I should use getThumbnail and return DropboxFileInfo to the webpage on client side??? I just want to return a small thumbnail to show on the webpage not intend to save to anywhere. – Takumi Sep 25 '12 at 09:25
  • If the entire call is to get this image then you need to use `getThumbnailStream` which gives you the DropboxInputStream. read the data from it and write this data to the `HTTPResponse` object in the Servlet. and then set the appropriate HTTP headers to represent what kind of image the response is. – arikg Sep 25 '12 at 09:27
  • As stated below have a look at http://stackoverflow.com/questions/1232591/displaying-image-in-html-and-jsp-code – dngfng Sep 25 '12 at 09:35
  • Thank you I will try...but honestly even I don't understand that much but in concept I do... – Takumi Sep 25 '12 at 09:58
0

You should be able to read the Image with ImageIO.read

Image image = ImageIO.read(dis);

http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html

dngfng
  • 1,923
  • 17
  • 34
  • In a JSP you could do somthing like this: http://stackoverflow.com/questions/1232591/displaying-image-in-html-and-jsp-code replacing the loading of the inputstream with the DropboxInputStream – dngfng Sep 25 '12 at 09:33