第一次用七牛, java写了一个test
但是调用上传方法时,报错,从官方复制下来的图片也一样报错 ,是不是main中不能直接调用?
package com.meiyi.interfaces;
import java.io.IOException;
import com.meiyi.utils.Host;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
public class test {
//上传到七牛后保存的文件名
String key = "my-java-gyy.png";
//上传文件的路径
String FilePath = "E:\\gyy.jpg";
//密钥配置
Auth auth = Auth.create(Host.ACCESS_KEY, Host.SECRET_KEY);
//创建上传对象
UploadManager uploadManager = new UploadManager();
//简单上传,使用默认策略,只需要设置上传的空间名就可以了
public String getUpToken(){
return auth.uploadToken(Host.bucketname);
}
public void upload() throws IOException{
try {
//调用put方法上传
Response res = uploadManager.put(FilePath, key, 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
}
}
}
/**
@param args
@throws IOException
*/
static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
test t = new test();
t.upload();
}
}
这是错误信息
ClassNotFoundException
It is recommended that you check out the jar package related to okhttp3Thank you, although there is sdk, there are still related jars missing