上传图片出错
源码:
package action;
import java.io.IOException;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Client;
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 = "Qq7fV0IafjldakjAWoI0hbQFlgzGfffZvcsaCh708sLQotsRGCE";
String SECRET_KEY = "9dA4IuUPafmdlakjfDpJmmicSqAIlEFWvZdzKXvVKJPifYqxE";
//要上传的空间
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();
}*/
Client httpManager = new Client();
Response r = null;
try {
r = httpManager.post("http://www.baidu.com", "hello", null);
//Assert.assertNull(r.reqId);
} 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: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.post(Client.java:132)
at com.qiniu.http.Client.post(Client.java:115)
at com.qiniu.http.Client.post(Client.java:93)
at action.UploadAction.main(UploadAction.java:66)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码有问题的吧,你要把文件转成流