拿到 response.getEntity() 之后
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream result = response.getEntity().getContent();
int len = 0;
while ((len = result.read()) != -1) {
out.write(len);
}
return out.toByteArray();
直接虚区到前台
得到的byte[] 通过七牛上传,简单粗糙实现一下:
Configuration cfg = new Configuration(Zone.zone0());
UploadManager uploadManager = new UploadManager(cfg);
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(b);
Auth auth = Auth.create(QiniuConfig.ACCESSKEY, QiniuConfig.SECRETKEY);
String upToken = auth.uploadToken(QiniuConfig.BUCKET);
Response response = uploadManager.put(byteInputStream, key, upToken, null, null);
//解析上传成功的结果
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
System.out.println(putRet.key);
欧克,打印出来的就是图片的key啦