问题描述
我在名为 file 的JSON密钥中将图像作为base64编码的字符串接收。
{
"fileName":"Feedback_image.jpg","file":" // image data being sent from android "
}
我正在使用解码功能在服务器端对base64编码的字符串进行解码。
byte[] imageByteArray = Base64.getDecoder().decode(imageUploadDTO.getFile());
我什至可以将图像写入Windows,然后成功创建图像。现在,我面临的问题是我必须将图像作为多部分实体发送到第三方POst API。 我正在尝试使用以下代码形成HttpPost,但该图像未正确发送到第三方服务器。
public HttpPost getHttpPostRequest(String requestUrl,byte[] imageByteArray,String fileName) throws Exception {
HttpPost httpPostRequest = new HttpPost(requestUrl);
httpPostRequest.addHeader(CRGERaagaAppConstants.CONTENT_TYPE,MediaType.MULTIPART_FORM_DATA);
multipartentityBuilder builder = multipartentityBuilder.create();
ContentBody cd = new InputStreamBody(new ByteArrayInputStream(imageByteArray),fileName);
builder.addPart("fileName",cd);
httpentity entity = builder.build();
httpPostRequest.setEntity(entity);
return httpPostRequest;
}
有人可以告诉我如何从base64编码的字符串中正确检索图像内容并将其发送到HttpPost吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)