서버로 이미지와 텍스트 2개를 한번에 보내려고 합니다.
일단 아래는 텍스트 전송 부분까지의 코드입니다.
String absolutePath;
int maxBufferSize = 1 * 1024 * 1024;
int bufferSize;
String crlf = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
public String doInBackground(String... params){
try {
URL url = new URL(params[0]);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setConnectTimeout(5000);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream ds = new DataOutputStream(conn.getOutputStream());
FileInputStream mFileInputStream = new FileInputStream(absolutePath);
// 일반 텍스트 전송(String) 1
// 같은 형태로 계속해서 데이터 추가
ds.writeBytes(twoHyphens + boundary + this.crlf);
ds.writeBytes("Content-Disposition: form-data; name=\"bucketName\"" + this.crlf);
ds.writeBytes(this.crlf);
ds.writeBytes("heesu1220-nate-com" + this.crlf);
// 일반 텍스트 전송(String) 2
ds.writeBytes(twoHyphens + boundary + this.crlf);
ds.writeBytes("Content-Disposition: form-data; name=\"plantName\"" + this.crlf);
ds.writeBytes(this.crlf);
ds.writeBytes("dddddddddddddaaaaaaaaaaa" + this.crlf);
// 일반 텍스트 전송(String) 2
ds.writeBytes(twoHyphens + boundary + this.crlf);
ds.writeBytes("Content-Disposition: form-data; name=\"comments\"" + this.crlf);
ds.writeBytes(this.crlf);
ds.writeBytes("ddddd" + this.crlf);
absolutePath 스트링 변수에 사진첩 이미지의 절대경로가 들어있습니다.
이것을 이용하여 갤러리 이미지도 추가 전송할수있는 방법이 있을까요?