2

I'm trying to get a URL of a local image file in Android Gallery. I've tried formats like

file:///mnt/sdcard/test.jpg

or like

content://media/external/images/media/1

but none of them works. I'm just wondering if anyone can give me a properly formatted Android local file URL example? I need this to upload photo while checking in using Facebook api. thank you very much

noamtm
  • 12,435
  • 15
  • 71
  • 107
Allan Jiang
  • 11,063
  • 27
  • 104
  • 165
  • Your format is right. What problem do you get? – Jett Hsieh Aug 09 '11 at 03:41
  • thank you @Jett Hsieh and Earl my error(response from facebook) is "08-09 11:39:04.812: DEBUG/onComplete(3117): {"error":{"type":"OAuthException","message":"(#100) picture URL is not properly formatted"}} " – Allan Jiang Aug 09 '11 at 03:46
  • I am not familiar with FB API. But I think what it needs is real URL, which starts with "http", not an URI in the local device. – Jett Hsieh Aug 09 '11 at 03:55
  • @Jett Hesieh Yea that's exactly what I'm thinking about... but I know we can use something like "file:\\\" to represent a local file in URL way in computers so just trying if this would be still work on android... thank you very much though – Allan Jiang Aug 09 '11 at 04:08
  • file:///mnt/sdcard/test.jpg is correct, try it in Browser – Diego Torres Milano Aug 09 '11 at 04:12
  • This question is badly titled; the provided local file URL is correct, but Facebook API can't work with it (the accepted answers explains why). I fixed the title, as this question doesn't help those who wonder about Android file URLs. – noamtm Jul 17 '16 at 06:25

3 Answers3

4

Facebook API can't use your local file URI as it doesn't have access to the contents of your phone. You need to use a POST request to physically upload the contents of your file.

dragonroot
  • 5,653
  • 3
  • 38
  • 63
0

If I'm not mistaken UNIX paths go like this:

/mnt/sdcard/test.jpg
nkcmr
  • 10,690
  • 25
  • 63
  • 84
  • @sightofnick Hi thank you for your answer. This was the first thing I tried, and got a response of "picture URL is not properly formatted". – Allan Jiang Aug 09 '11 at 03:41
0

Absolute Path Environment.getExternalStorageDirectory().getAbsolutePath() gives to absolute path to SDCard. From here "/DCIM/Camera/" would give you the path to folder used by Camera to store captured image.

So your file path would be something like this

String mBaseFolderPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/";
String filePath = mBaseFolderPath  + "test.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(filePath);

Content Resolver Path content://media/external/images/media/1 is the path referred by content resolver. This is like MediaStore.Images.Media.EXTERNAL_CONTENT_URI + Image Id

If you get hold of Uri of the image then you can use the following to get bitmap correspondong to the image.

Bitmap someBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), url);

Shash

Shash316
  • 2,218
  • 18
  • 19
  • Hi thank you for your answer. I tried both of them but failed. got the same response of " picture URL is not properly formatted" – Allan Jiang Aug 09 '11 at 04:09