- 申请测试公众号
- 利用测试公重号发布消息,报{"errcode":40113,"errmsg":"unsupported file type hint: [xxa009498677] rid: 6285f41d-0d4c84df-20472d8c"}
不支持文件类型,新增永久封面图不支持?thumb
public String testUpload(String path, String type) {
File file = new File(path);
url = url.replace("ACCESS_TOKEN", token).replace("TYPE", type);
try {
URL urlObj = new URL(url);
HttpsURLConnection urlConnection = (HttpsURLConnection) urlObj.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Connection", "Keep-Alive");
urlConnection.setRequestProperty("Charset", "utf8");
String boundary = "-----" + System.nanoTime();
urlConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
out = urlConnection.getOutputStream();
InputStream inputStream = new FileInputStream(file);
StringBuilder sb = new StringBuilder();
sb.append("--");
sb.append(boundary);
sb.append("\r\n");
sb.append("Content-Disposition:form-data;name=\"media\";filename=\"" + file.getName() +"\"\r\n");
sb.append("Content-Type:application/octet-stream\r\n\r\n");
System.out.println("stringBuilder is: "+ sb);
out.write(sb.toString().getBytes());
byte[] b= new byte[1024];
int len;
while ((len = inputStream.read(b)) != -1){
out.write(b,0,len);
}
String foot = "\r\n--"+boundary + "--\r\n";
out.write(foot.getBytes());
out.flush();
out.close();
StringBuilder res = new StringBuilder();
InputStream ins = urlConnection.getInputStream();
while ((len = ins.read(b)) != -1){
res.append(new String(b,0,len));
}
return res.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "no";
}
@Test
public void testUploadTmpFile(){
String path = "C:\\Users\\34743\\Desktop\\ma.jpg";
String res = testUpload(path, "thumb");
System.out.println(res);
}
你好,可以使用接口去获取素材,看看是否能获取到呢?
我也遇到这个问题了
解决了吗