0
有一個圖像列表,我想上傳到服務器Android的多上傳與圖像列表
我使用httpmime,這裏是代碼:
for(File file : gs.id_img) {
builder.addPart("id_img[]", new FileBody(file));
}
但在後端似乎無法獲得發佈的價值,如何解決它?感謝
有一個圖像列表,我想上傳到服務器Android的多上傳與圖像列表
我使用httpmime,這裏是代碼:
for(File file : gs.id_img) {
builder.addPart("id_img[]", new FileBody(file));
}
但在後端似乎無法獲得發佈的價值,如何解決它?感謝
你有這樣
public void connectForMultipart() throws Exception {
con = (HttpURLConnection) (new URL(url)).openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
con.connect();
os = con.getOutputStream();
}
public void addFormPart(String paramName, String value) throws Exception {
writeParamData(paramName, value);
}
public void addFilePart(String paramName, String fileName, byte[] data) throws Exception {
os.write((delimiter + boundary + "\r\n").getBytes());
os.write(("Content-Disposition: form-data; name=\"" + paramName + "\"; filename=\"" + fileName + "\"\r\n" ).getBytes());
os.write(("Content-Type: application/octet-stream\r\n" ).getBytes());
os.write(("Content-Transfer-Encoding: binary\r\n" ).getBytes());
os.write("\r\n".getBytes());
os.write(data);
os.write("\r\n".getBytes());
}
public void finishMultipart() throws Exception {
os.write((delimiter + boundary + delimiter + "\r\n").getBytes());
}
工作,我已經改變了Content-Type: application/octet-stream\r\n"
到Content-Type: image/jpeg\r\n\r\n
和它的工作:)