按照官网给的例子,
jar包:okhttp-2.3.0-SNAPSHOT.jar okio-1.3.0-SNAPSHOT.jar
qiniu-java-sdk-7.10.jar qiniu-java-sdk-7.10-sources.jar
gson-2.2.1.jar
上传回调方法如下:
public class qiniuUploadAction {
//设置好账号的ACCESS_KEY和SECRET_KEY
String ACCESS_KEY = "l7TEvUA-XlHQuZBZrLkRhbEi2syozzsGmgKa0ZBv";
String SECRET_KEY = "F2bAE9PJCIzL7pLMqnXfY_mQd-l3kmDRdKpl3eWn";
//要上传的空间
String bucketname = "image20160623";
//上传到七牛后保存的文件名
String key = "my-java.png";
//上传文件的路径
String FilePath = "http://127.0.0.1:8080/wcmsadmin/upload/20160313143057.jpg";
//密钥配置
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
//创建上传对象
UploadManager uploadManager = new UploadManager();
//设置callbackUrl以及callbackBody,七牛将文件名和文件大小回调给业务服务器
public String getUpToken(){
return auth.uploadToken(bucketname,null,3600,new StringMap()
.put("callbackUrl","http://your.domain.com/callback")
.put("callbackBody", "filename=$(fname)&filesize=$(fsize)"));
}
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[]) throws IOException{
qiniuUploadAction ss =new qiniuUploadAction();
ss.upload();
}
}
运行报错:
请各位大神,指点迷津,谢谢