开发平台调用提审素材上传接口为什么报错:41005?
{\“errcode\”:41005,\“errmsg\”:\“media data missing rid: 606eaaba-107d1813-545d7140\”}
2 回复
解决了。得用原始的请求。
public static String uploadmedia(String authorizerAccessToken, MultipartFile mediaFile) {
try {
URL urlObj = new URL("https://api.weixin.qq.com/wxa/uploadmedia?access_token=" + authorizerAccessToken);
HttpURLConnection conn = (HttpURLConnection)urlObj.openConnection();
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
String BOUNDARY = "----------" + System.currentTimeMillis();
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY);
StringBuilder sb = new StringBuilder();
sb.append("--");
sb.append(BOUNDARY);
sb.append("\r\n");
sb.append("Content-Disposition:form-data;name=\"media\";filename=\"" + mediaFile.getOriginalFilename() + "\";filelength=\"" + mediaFile.getSize() + "\"\r\n");
sb.append("Content-Type:application/octet-stream\r\n\r\n");
byte[] head = sb.toString().getBytes("utf-8");
OutputStream out = new DataOutputStream(conn.getOutputStream());
out.write(head);
out.write(mediaFile.getBytes());
byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");
out.write(foot);
out.flush();
out.close();
StringBuffer buffer = new StringBuffer();
BufferedReader reader = null;
String result = null;
try {
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
while((line = reader.readLine()) != null) {
buffer.append(line);
}
if (result == null) {
result = buffer.toString();
}
} catch (IOException var17) {
var17.printStackTrace();
} finally {
reader.close();
}
return result;
} catch (IOException var19) {
logger.error(BizLog.buildLogInfo("uploadmedia: " + ExceptionUtils.getStackTrace(var19)));
return null;
}
}