Java Code Examples for com.qiniu.common.QiniuException#toString()
The following examples show how to use
com.qiniu.common.QiniuException#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QiniuUtil.java From BigDataPlatform with GNU General Public License v3.0 | 6 votes |
/** * 文件流上传 * @param file * @param key 文件名 * @return */ public static String qiniuInputStreamUpload(FileInputStream file, String key){ //构造一个带指定Zone对象的配置类 zone2华南 Configuration cfg = new Configuration(Zone.zone2()); UploadManager uploadManager = new UploadManager(cfg); Auth auth = Auth.create(accessKey, secretKey); String upToken = auth.uploadToken(bucket); try { Response response = uploadManager.put(file,key,upToken,null, null); //解析上传成功的结果 DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class); return origin+putRet.key; } catch (QiniuException ex) { Response r = ex.response; log.warn(r.toString()); try { return r.bodyString(); } catch (QiniuException e) { throw new XmallUploadException(e.toString()); } } }
Example 2
Source File: FileService.java From ml-blog with MIT License | 6 votes |
/** * 文件删除 * @param key * @return */ public Response delete(String key) throws GlobalException{ // 有配置数据,但上传凭证为空 if (!commonMap.containsKey("upToken")) { // 创建七牛云组件 createQiniuComponent(); } try { BucketManager bucketManager = (BucketManager) commonMap.get("bucketManager"); String bucket = commonMap.get("qn_bucket").toString(); Response response = bucketManager.delete(bucket, key); int retry = 0; while(response.needRetry() && retry < 3) { response = bucketManager.delete(bucket, key); retry++; } return response; } catch (QiniuException ex) { log.error("文件删除异常:",ex.toString()); throw new GlobalException(500, ex.toString()); } }
Example 3
Source File: QiniuUtil.java From BigDataPlatform with GNU General Public License v3.0 | 5 votes |
public static String qiniuUpload(String filePath){ //构造一个带指定Zone对象的配置类 zone2华南 Configuration cfg = new Configuration(Zone.zone2()); UploadManager uploadManager = new UploadManager(cfg); String localFilePath = filePath; //默认不指定key的情况下,以文件内容的hash值作为文件名 String key = null; Auth auth = Auth.create(accessKey, secretKey); String upToken = auth.uploadToken(bucket); try { Response response = uploadManager.put(localFilePath, key, upToken); //解析上传成功的结果 DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class); return origin+putRet.key; }catch(QiniuException ex){ Response r = ex.response; log.warn(r.toString()); try { return r.bodyString(); } catch (QiniuException e) { throw new XmallUploadException(e.toString()); } } }
Example 4
Source File: FileService.java From ml-blog with MIT License | 5 votes |
/** * 文件上传 * @param inputStream * @param filename * @return */ public Response upload(InputStream inputStream, String filename) throws GlobalException{ // 有配置数据,但上传凭证为空 if (!commonMap.containsKey("upToken")) { // 创建七牛云组件 createQiniuComponent(); } try { String upToken = (String) commonMap.get("upToken"); UploadManager uploadManager = (UploadManager) commonMap.get("uploadManager"); // 上传 Response response = uploadManager.put(inputStream,filename,upToken,null, null); int retry = 0; while(response.needRetry() && retry < 3) { response = uploadManager.put(inputStream,filename,upToken,null, null); retry++; } return response; } catch (QiniuException ex) { Response r = ex.response; log.error("文件上传异常:",r.toString()); throw new GlobalException(500, ex.toString()); } }