七牛云

来源:互联网 发布:js string转date函数 编辑:程序博客网 时间:2024/06/05 02:45

http://jsfiddle.net/rwifeng/7rgqzpb0/3/#run  token生成地址

public class QnUpDown {   public static  void init(){        Configuration config = new Configuration.Builder()                .chunkSize(256 * 1024)  //分片上传时,每片的大小。 默认256K                .putThreshhold(512 * 1024)  // 启用分片上传阀值。默认512K                .connectTimeout(10) // 链接超时。默认10秒                .responseTimeout(60) // 服务器响应超时。默认60秒                .recorder(null)  // recorder分片上传时,已上传片记录器。默认null                .recorder(null, null)  // keyGen 分片上传时,生成标识符,用于片记录器区分是那个文件的上传记录                .zone(null) // 设置区域,指定不同区域的上传域名、备用域名、备用IP。                .build();        // 重用uploadManager。一般地,只需要创建一个uploadManager对象         uploadManager = new UploadManager(config);    }  private  static UploadManager uploadManager;    /*上传文件*/   public static void upLoading(Context context){       File  file =new File(context.getFilesDir(),"phoneX.jpg");       SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");       String key = "icon_" + sdf.format(new Date());       String token = "iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV:3j8sc3Hp280fBA87K25fyP8shSc" +               "=:eyJzY29wZSI6InF0ZXN0YnVja2V0IiwiZGVhZGxpbmUiOjE0OTg3MzY5Mzd9";       uploadManager.put(file, key, token,               new UpCompletionHandler() {                   @Override                   public void complete(String key, ResponseInfo info, JSONObject res) {                       //res包含hash、key等信息,具体字段取决于上传策略的设置                       Logger.soutMessage(info.toString());                       if (key!=null){                           Logger.soutMessage(key.toString());                       }                       if (res!=null){                           Logger.soutMessage(res.toString());                       }                       if(info.isOK())                       {                           Logger.soutMessage("pass");                       }                       else{                           Logger.soutMessage("fail");                           //如果失败,这里可以把info信息上报自己的服务器,便于后面分析上传错误原因                       }                       Logger.soutMessage("finish");                   }               }, null);   }    public static boolean saveImage(Context context) {        Bitmap  bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.g_a_axxhdpi);        FileOutputStream outputStream;        ByteArrayOutputStream out = new ByteArrayOutputStream();        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);        try {            out.flush();         //   if (getisFirst()){                outputStream = context.openFileOutput("testb.jpg", Context.MODE_PRIVATE);          /*  }else {                outputStream = openFileOutput("phoneY.jpg", Context.MODE_PRIVATE);            }*/            out.writeTo(outputStream);            out.close();            outputStream.close();        } catch (IOException e) {            e.printStackTrace();            return false;        }        return true;    }}

原创粉丝点击