마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 .net multipart 에 관한 질문입니다~(소스 有)

0 추천

안녕하세요~ 제가 이미지 여러개를 안드로이드에서 보내고 서버에서 받으려 합니다.

이미지가 잘 넘어가는 것 같은데 서버에서 확인하는 방법을 몰라서 글을 남겨봅니다.

 

안드로이드 소스

 

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)
    {
        //어떻게 받아야할지 모르겠더라구요...
        
    }
}

 

익명사용자 님이 2016년 7월 26일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...