Menu

#6 Using URL for inputstream in image upload

open
nobody
None
5
2009-05-08
2009-05-08
No

I am creating an image upload capability for users of an online repository of photos and metadata of flora and fauna. I need to be able to use a repository URL as the source of the uploaded image.

Sample upload code:

static final String IMAGE_URL = "http://test.morphbank.net/?id=161245&imgType=jpg";
...
URL url = new URL(IMAGE_URL);
in = url.openStream();
...
String photoId = uploader.upload(in, metaData);

The writeParams method of class com.aetrion.flickr.REST does not properly process the InputStream of the java.net.URL object created from an image URL. This may be due to a problem with java.net.URL and not a problem with Flickrj. The code that reads from the InputStream is at line 268:

byte[] buf = new byte[512];
int res = -1;
while ((res = in.read(buf)) != -1) {
out.write(buf);
}

When I was unable to load images from URL to Flickr, I did some experiments to determine what was wrong. I wrote a simple test program to write a local file from an image URL using the byte[512] strategy of writeParams. The resulting file was larger than the original and the image was corrupted. Changing the definition of "buf" to "int" resolved the problem. The resulting loop is:

int buf;
while ((buf = in.read()) != -1) {
out.write(buf);
}

I suppose that the byte array in writeParams is intended to reduce the number of iterations. Unfortunately it also removes the image URL as a potential source for the upload.

I have modified my copy of the flickrj REST class to read 1 character at a time and look forward to hearing whether the problem I am having will be eliminated in a future release.

Thank you for your consideration
Greg Riccardi
Florida State University
http://www.morphbank.net

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.