안녕하세요~ 제가 이미지 여러개를 안드로이드에서 보내고 서버에서 받으려 합니다.
이미지가 잘 넘어가는 것 같은데 서버에서 확인하는 방법을 몰라서 글을 남겨봅니다.
안드로이드 소스
public void executeMultipartPost() throws Exception {
try {
// 생성
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setCharset(Charset.forName("UTF-8"));
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
// builder.addBinaryBody("data", file, org.apache.http.entity.ContentType.create("application/json", Consts.UTF_8), file.getName());
//서버에서 값을 찾을 수 없음.
builder.addPart("file", new ByteArrayBody(byteArray, "Img1.png"));
builder.addPart("file", new ByteArrayBody(byteArray2, "Img2.png"));
//Server 안타짐.
// String path = Environment.getExternalStorageDirectory().toString();
// FileBody bin = new FileBody(new File(path+"/test/fullImg.jpeg"));
// builder.addPart("bin", bin);
// 전송
InputStream inputStream = null;
HttpClient httpClient = AndroidHttpClient.newInstance("Android");
HttpPost httpPost = new HttpPost(UPLOAD_URL);
HttpEntity entity = builder.build();
httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
inputStream = httpEntity.getContent();
// 응답
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
StringBuilder stringBuilder = new StringBuilder();
String line = null;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
inputStream.close();
// 응답 결과
String result = stringBuilder.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
ASP.net 소스
public partial class Upload: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//어떻게 받아야할지 모르겠더라구요...
}
}