java上传图片到七牛,抛出异常
小白想用安卓上传图片到七牛,先用java试了下,但一直抛出异常,下面是我代码,后面给出异常信息
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
public class TestQiniu {
public static void main(String[] args) {
String uptoken=getUptoken();
System.out.println(uptoken);
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(new File("test.png"));
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream baos=new ByteArrayOutputStream();
try {
ImageIO.write(bufferedImage, "png", baos);
} catch (IOException e) {
e.printStackTrace();
}
new TestQiniu().upLoadPic(baos.toByteArray(), "test1", uptoken);
}
private static String getUptoken() {
Auth auth = Auth.create("8EqgYr4A18xyeUzWdDHt6OKTKJ5wW9mttLKiobF_",
"gFxrGJAGII497kyncBlZ7_V1GMEgqRW00ytXxg8q");
String uptoken = auth.uploadToken("agriculturetest","test_pic",3600,null);
return uptoken;
}
public void upLoadPic(byte[] data,String key,String token){
UploadManager uploadManager=new UploadManager();
try {
Response response= uploadManager.put(data, key, token);
System.out.println(response.isOK());
} catch (QiniuException e) {
e.printStackTrace();
}
}
}
Exception in thread "main" java.lang.IncompatibleClassChangeError: Found class com.squareup.okhttp.Connection, but interface was expected
at com.qiniu.http.Client$1.intercept(Client.java:39)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:868)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)
at com.squareup.okhttp.Call.getResponse(Call.java:268)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
at com.squareup.okhttp.Call.execute(Call.java:79)
at com.qiniu.http.Client.send(Client.java:195)
at com.qiniu.http.Client.multipartPost(Client.java:175)
at com.qiniu.http.Client.multipartPost(Client.java:143)
at com.qiniu.storage.FormUploader.upload(FormUploader.java:52)
at com.qiniu.storage.UploadManager.put(UploadManager.java:126)
at com.qiniu.storage.UploadManager.put(UploadManager.java:104)
at test.TestQiniu.upLoadPic(TestQiniu.java:46)
at test.TestQiniu.main(TestQiniu.java:32)
之前有帖子说是java-sdk 上传超时可能是由于 okhttp,okio 的版本问题引起,更换 okhttp 2.3 okio 1.6试下
我换了试过,也没用,还是同一个错,文档看了又看实在找不到问题,求解答。谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你好 请问你解决了吗
难道无解了?有解决的在这里说一下咯;
jdk1.6、sdk7.0.9.jar
有解了:把sdk换底一点:sdk7.0.1.jar
其他sdk版本没试过。
-----正解:
jdk1.6版本:对应的jar;【sdk或许其他版本也可以,这边没试过,就不说了。】
okhttp-2.3.0.jar
okio-1.3.jar
qiniu-java-sdk.7.0.1.jar