0

I'm trying to upload photo to Flickr, but this code is throwing an exception of file not found.The image is in the folder, but I don't know why Android is throwing an exception. Please help.

OAuthRequest request = new OAuthRequest(Verb.POST,
        "http://api.flickr.com/services/upload/");
service.signRequest(accessToken, request);
MultipartEntity entity = new MultipartEntity();
entity.addPart("photo", new FileBody(new File("/test/res/drawable-hdpi/icon.png"),
        "image/png"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
    entity.writeTo(out);
    request.addPayload(out.toByteArray());
    request.addHeader(entity.getContentType().getName(),
            entity.getContentType().getValue());

    Response response = request.send();
    String body = response.getBody();
} catch (IOException e) {
    e.printStackTrace();
}
Jelo Melo
  • 5
  • 2

2 Answers2

0

You can not access files located in drawable folder by their absolute path.

Instead try moving the picture in the /assets folder and access it by getAssets() or move it in /res/raw and access it by R.raw.icon.

niculare
  • 3,629
  • 1
  • 25
  • 39
0

Try opening your file with openRawResource(int id):

Open a data stream for reading a raw resource. This can only be used with resources whose value is the name of an asset files -- that is, it can be used to open drawable, sound, and raw resources; it will fail on string and color resources.

I think FileBody constructors don't accept an InputStream, so you'd likely need other methods to send the binary data (the file).