android 앱에서 /MNT/SDCARD
또는 ASSETS/FILES
폴더의 사진을 보내고 싶습니다.서버에 파일로드 및 저장 HTTP POST 요청
05-12 16:15:15.468: E/AndroidRuntime(17228): Caused by: java.io.FileNotFoundException: /data/data/com.example.app_flower3/files/qqqwww.png (No such file or directory)
05-12 16:15:15.468: E/AndroidRuntime(17228): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
05-12 16:39:20.417: E/AndroidRuntime(19575): Caused by: java.lang.IllegalArgumentException: File //mnt//sdcard//gauss.jpg contains a path separator
이 내 코드입니다 :
public Map<String,String> postSendImageAndGetJson() throws ParseException, FileNotFoundException
{
File rootPath=Environment.getExternalStorageDirectory();
Log.d("CILO",rootPath.getPath().toString());
printer.log("CHESTIE!!");
// Create map
Map<String,String> map = new TreeMap<String,String>();
BufferedInputStream buf = new BufferedInputStream(context.openFileInput("//mnt//sdcard//gauss.jpg"));
Bitmap bitmapOrg = BitmapFactory.decodeStream(buf);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
String upload_url = "http://www.aplicatii-iphone.ro/android/test.php"; // HARDCODED
bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
byte[] data = bao.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(upload_url); // HARDCODED
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
//Set Data and Content-type header for the image
entity.addPart("file",
new ByteArrayBody(data, "image/jpeg", "file"));
postRequest.setEntity(entity);
try
{
HttpResponse response = httpClient.execute(postRequest);
//Read the response
String jsonString = EntityUtils.toString(response.getEntity());
Log.d("CILO", "after uploading file "+ jsonString);
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return map;
}
- 내가 실수를 않습니다 나는 오류의 그 종류는 무엇입니까?
- 인터넷에서 검색 한 결과, 안드로이드 앱 (이미지)에 대한 데이터 작업에 대한 유용한 자습서를 어디에서 찾을 수 있습니까?
감사합니다.
'BufferedInputStream buf = 새로운 BufferedInputStream (새 InputStream (sdFile));'이 오류가 발생합니다,'BufferedInputStream' 생성자는'InputStream' 객체 만 받아들이십시오. 완전한 코드가 있습니까? 고맙습니다. – Master345
내가 만든 편집을 확인하고, 잘하면 그것을 정리해야합니다. 행운을 빕니다 – bkane521