private void doFileUpload(){
File file1 = new File(selectedPath1);
String urlString = "http://184.169.137.212/upload_media_test.php";
try
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlString);
FileBody bin1 = new FileBody(file1);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("uploadedfile1", bin1);
reqEntity.addPart("user", new StringBody("User"));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
resEntity = response.getEntity();
final String response_str = EntityUtils.toString(resEntity);
if (resEntity != null) {
Log.i("RESPONSE",response_str);
runOnUiThread(new Runnable(){
public void run() {
try {
res.setTextColor(Color.GREEN);
res.setText("n Response from server : n " + response_str);
Toast.makeText(getApplicationContext(),"Upload Complete. Check the server uploads directory.", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
catch (Exception ex){
Log.e("Debug", "error: " + ex.getMessage(), ex);
}
}
위의 코드를 인터넷에 받아 갤러리에서 사진을 선택하고 그 목록을 가지고 사진을 업로드하는 방법을 구현하고 있습니다.
그런데, 사진이 커서 업로드할때 문제가 생겨서 리사이징 후에 사진을 업로드해야 될것 같습니다.
그런데, 지금 소스는 File Path를 받아서 Bitmap으로 변환해서 리사이징하고
다시 reqEntity.addPart("uploadedfile1", bin1); 형태로 전송하는 방법이 궁금합니다.
미리 답변 감사합니다.