java测试图片上传到七牛,不成功
大家讲道理
大家讲道理 2017-04-18 09:28:57
0
2
505

第一次用七牛, 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
      */

    1. static void main(String[] args) throws IOException {

         // TODO Auto-generated method stub
           test t = new test();
           t.upload();

      }

    }

    这是错误信息

    大家讲道理
    大家讲道理

    光阴似箭催人老,日月如移越少年。

    reply all(2)
    伊谢尔伦

    ClassNotFoundException It is recommended that you check out the jar package related to okhttp3

    洪涛

    Thank you, although there is sdk, there are still related jars missing

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!