1

I use dropbox api, and created shareable Url to an image

After loading the url in browser I got html page that contains that image, while I need only the image link.

In the html page source in browser here's the link of the image:

<img class="preview-image absolute-center" src="<IMG-LINK>" style="visibility: visible;" data-reactid=".1.0.0">

but when I try to get the content of the url in java servlet I find that there's no image in the content

URL url= new URL("<dropbox-shareable-url>");
String content = IOUtils.toString(url);

I think the url page first should be loaded to get the image link i need.

Is there anyway to connect and load the url before getting the content in java?

Sherein
  • 947
  • 1
  • 11
  • 23
  • 2
    Please visit the [help] to see what and how to ask. As it stands there is too little code and explanation to clearly understand your problem – mplungjan Jan 14 '16 at 13:28
  • You have to call that url with something like an HTTP client to get its content and then do whatever you want with it. – Gaël J Jan 14 '16 at 13:38
  • 1
    Possible duplicate of [Read url to string in few lines of java code](http://stackoverflow.com/questions/4328711/read-url-to-string-in-few-lines-of-java-code) – Gaël J Jan 14 '16 at 13:38

1 Answers1

0

I don't know if this still works, but try to replace
www.dropbox.com
with:
dl.dropboxusercontent.com

Then you can fetch the direct image.
As an image:

Image img = ImageIO.read(url)

Or you could use Apache Commons IO FileUtils to directly save to a File:

FileUtils.copyURLToFile(url, file)
Leet-Falcon
  • 2,107
  • 2
  • 15
  • 23
  • replaced www.dropbox.com with dl.dropboxusercontent.com and it workes and i got the image! thank you – Sherein Jan 14 '16 at 17:49