im trying to do a file upload using http post but when I try to use a file from the micro-sd card on my phone, it doesn’t create it so that I can upload it. It works perfectly when selecting files from the main phone storage, just not the sd card.
Im using an external library for the file selection dialog, which returns this when I try to select an image from the sd card (in this example its a photo taken from the camera app):
/sdcard-ext/dcim/Camera/2012-07-02_12-28-19_548.jpg
This is returned from just a random image I found in the OS files on the phone:
/sdcard/DCIM/.thumbnails/1331049921270.jpg I know this one looks like its on an sd card too (or at least it does to me), but this is definitely the phone’s storage.
Here is the code I am currently using for the file upload:
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(myURL);
MultipartEntity mp = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
String mimeType = getFileMimeType(filePath);//the filePath is passed to the function
that this code is contained inside and is initially sent from the file selection dialog
mp.addPart("fileupload", new FileBody(new File(filePath), mimeType));
httppost.setEntity(mp);
String response = EntityUtils.toString( httpclient.execute( httppost ).getEntity(), "UTF-8" );
System.out.println(response);
httpclient.getConnectionManager().shutdown();
If any of could explain why this works for the phone’s internal storage and not the removable sd card, that would be great!
Thanks.
UPDATE: I’m targeting Android 2.2 if that makes any difference. If it doesn’t make any difference, I’m still targeting Android 2.2
Add
Note: You should also see a “permission denied” error in the logcat, which should have alerted you to this problem.
EDIT:
Sorry, to just read from the external storage you need: