整个过程完美无缺,除了图像不显示,没有错误,使用RoR。我错过了什么?全部由异步类btw调用。一直尝试几种不同的方法无济于事,如果有人可以帮助我,这将是伟大的。如果需要,愿意发布更多内容。
谢谢!
public static void multiPart(Bitmap image, String topicid, String topost, Context c){
String responseString = "";
{
try {
String imageName = System.currentTimeMillis() + ".jpg";
HttpClient httpClient = new MyHttpClient(c);
HttpPost postRequest = new HttpPost("https://urlofmyapi");
if (image==null){
Log.d("TAG", "NULL IMAGE");
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
image.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
ByteArrayBody bab = new ByteArrayBody(data, imageName);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("feed", new StringBody(topost));
reqEntity.addPart("post_to", new StringBody(topicid));
reqEntity.addPart("upload_file", bab);
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
responseString = s.toString();
System.out.println("Response: " + responseString);
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage());
}
}
}
答案 0 :(得分:2)
也许您可以执行以下步骤将库导入Android。
需求库:
httpmime-4.0.1.jar
谢谢,
Jenz
答案 1 :(得分:0)
HTTP将图像从Java发布到RoR似乎总是对我来说有不适当的问题。您是否尝试将二进制文件作为org.apache.http.entity.mime.content.FileBody
对象附加,例如此Android Multipart Upload问题?