일단 제가 만들고있는것은 이미지업로드가되는 게시판형태입니다.
그러기위에서는 텍스트와 이미지가 함께 업로드 되어야합니다.
현제 텍스트 따로 업로드가되고
이밎도 앨범에서 꺼내서 따로 어보드가됩니다. 물론 이미지 경로와 이름도 업로드되구요.
근대 두개를 함께 업로드할려니 안되네요;;
multipart/form-data
형태로 이미지를 업로드하고
application/x-www-form-urlencoded
형태로 텍스트를 업로드했는데.
두개를 함께 사용할순 없나요?
multipart/form-data
만 사용해서 이미지와 텍스트 둘다 업로드가능한가요?
혹시나해서 소스 올리겠습니다.
private void DoFileUpload(String filePath) throws IOException {
HttpFileUpload("http://203.241.246.113/up.php", "", filePath);
}
private void HttpFileUpload(String urlString, String params, String fileName) {
try {
mFileInputStream = new FileInputStream(fileName);
connectUrl = new URL("urlString);
Log.d("Test", "mFileInputStream is " + mFileInputStream);
// open connection
HttpURLConnection conn = (HttpURLConnection)connectUrl.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
// write data
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + fileName+"\"" + lineEnd);
dos.writeBytes(lineEnd);
int bytesAvailable = mFileInputStream.available();
int maxBufferSize = 2048;
int bufferSize = Math.min(bytesAvailable, maxBufferSize);
byte[] buffer1 = new byte[bufferSize];
int bytesRead = mFileInputStream.read(buffer1, 0, bufferSize);
Log.d("Test", "image byte is " + bytesRead);
// read image
while (bytesRead > 0) {
dos.write(buffer1, 0, bufferSize);
bytesAvailable = mFileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = mFileInputStream.read(buffer1, 0, bufferSize);
}
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
//////////////////////////////////////////////////////
StringBuffer buffer = new StringBuffer();
buffer.append("title").append("=").append(mytitle).append("&"); // php 변수에 값 대입
buffer.append("pname").append("=").append(mypname).append("&"); // php 변수 앞에 '$' 붙이지 않는다
buffer.append("phone").append("=").append(myphone).append("&");
buffer.append("ga").append("=").append(myga).append("&");// 변수 구분은 '&' 사용
buffer.append("content").append("=").append(mycontent).append("&");
OutputStreamWriter outStream = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
PrintWriter writer = new PrintWriter(outStream);
writer.write(buffer.toString());
writer.flush();
Toast.makeText(up.this, "등록이 완료되었습니다.", 0).show();
// close streams
Log.e("Test" , "File is written");
mFileInputStream.close();
dos.flush(); // finish upload...
// get response
int ch;
InputStream is = conn.getInputStream();
StringBuffer b =new StringBuffer();
while( ( ch = is.read() ) != -1 ){
b.append( (char)ch );
}
Log.e("Test", "result = hhhh");
dos.close();
} catch (Exception e) {
Log.d("Test", "exception " + e.getMessage());
// TODO: handle exception
}
}
이렇게하니. 텍스트만 업로드 되네요...
문제점쫌 알려주세요 부탁드립니다. 졸작이 10일남앗는대 큰일이내요;;;