小程序
小游戏
企业微信
微信支付
扫描小程序码分享
{\"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; } }
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
没有正确传递文件内容吧?
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
解决了。得用原始的请求。 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; } }
没有正确传递文件内容吧?
public static String uploadmedia(String authorizerAccessToken, MultipartFile mediaFile){
try {
MultipartEntityBuilder builder = MultipartEntityBuilder.create()
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
.setCharset(Charset.forName("utf-8"));
builder.addBinaryBody("media", mediaFile.getBytes(),ContentType.create(mediaFile.getContentType()),mediaFile.getOriginalFilename());
String result = Request.Post("https://api.weixin.qq.com/wxa/uploadmedia?access_token="+authorizerAccessToken)
.body(builder.build())
.execute().returnContent().asString();
logger.info(BizLog.buildLogInfo("uploadmedia,result: "+result));
return result;
} catch (IOException e) {
logger.error(BizLog.buildLogInfo("uploadmedia: "+ ExceptionUtils.getStackTrace(e)));
}
return null;
}