我正在尝试使用http post上传文件,但当我尝试在手机上使用micro-SD卡中的文件时,它不会创建它以便我可以上传它。它完美地工作时,选择文件从主手机存储,而不是SD卡。
我正在为文件选择对话框使用一个外部库,当我试图从SD卡中选择一个图像(在本例中是从相机应用程序中拍摄的一张照片)时,它会返回以下内容:/sdcard-ext/dcim/Camera/2012-07-02_12-28-19_548.jpg
这是从我在手机操作系统文件中找到的一个随机图像返回的:/sdcard/DCIM/.thumbnails/1331049921270.jpg我知道这张图片看起来也像是在SD卡上(至少对我来说是这样),但这绝对是手机的存储空间。
这是我目前用来上传文件的代码:DefaultHttpClient= httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,DefaultHttpClient();HttpClient 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();如果其中任何一个可以解释为什么这适用于手机的内部存储,而不是可移动的SD卡,那就太好了!谢谢。
更新:我的目标是Android 2.2,如果这有什么不同的话。如果没有什么不同,我的目标仍然是Android2.2
发布于 2012-07-04 17:33:53
添加
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />注意:您还应该在logcat中看到一个“权限被拒绝”的错误,它应该已经提醒您注意这个问题。
EDIT:对不起,只读你需要的外部存储器:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />https://stackoverflow.com/questions/11300121
复制相似问题