七牛上传文件出错
源代码:
package action;
import java.io.IOException;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
public class UploadAction {
public UploadAction() {
// TODO Auto-generated constructor stub
}
//设置好账号的ACCESS_KEY和SECRET_KEY
String ACCESS_KEY = "Qq7fV0IAWoI0hbQFlrqewqjflfgzGZvcsaCh708sLQotsRGCE";
String SECRET_KEY = "9dA4IuUPDpJmmicSqakjflakjAIlEFWvZdzKXvVKJPifYqxE";
//要上传的空间
String bucketname = "picture";
//上传到七牛后保存的文件名
String key = "blog.jpg";
//上传文件的路径
String FilePath = "D://blog.jpg";
//密钥配置
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
//创建上传对象
UploadManager uploadManager = new UploadManager();
//简单上传,使用默认策略,只需要设置上传的空间名就可以了
public String getUpToken(){
return auth.uploadToken(bucketname);
}
public void upload() throws IOException{
try {
//调用put方法上传
Response res = uploadManager.put(FilePath, null, getUpToken());
//打印返回的信息
System.out.println(res.bodyString());
} catch (QiniuException e) {
Response r = e.response;
// 请求失败时打印的异常的信息
System.out.println(r.toString());
try {
//响应的文本信息
System.out.println(r.bodyString());
} catch (QiniuException e1) {
//ignore
}
}
}
public static void main(String[] args) {
try {
new UploadAction().upload();
} catch (IOException e) {
// TODO Auto-generated catch block
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:802)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:683)
at com.squareup.okhttp.Call.getResponse(Call.java:272)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:228)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:199)
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:154)
at com.qiniu.storage.FormUploader.upload(FormUploader.java:54)
at com.qiniu.storage.UploadManager.put(UploadManager.java:184)
at com.qiniu.storage.UploadManager.put(UploadManager.java:152)
at com.qiniu.storage.UploadManager.put(UploadManager.java:137)
at action.UploadAction.upload(UploadAction.java:39)
at action.UploadAction.main(UploadAction.java:57)
按照相关解决方案,已经换了好几个okhttp版本还是不行。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前是用的java-sdk、okhttp 、okio、gjson 各是什么版本?