com.jeesuite.filesystem.UploadTokenParam Java Examples

The following examples show how to use com.jeesuite.filesystem.UploadTokenParam. 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: FileController.java    From oneplatform with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "uptoken", method = RequestMethod.GET)
	@ApiOperation(value = "生成上传凭证")
	@ApiImplicitParams({
		 @ApiImplicitParam(paramType="query",name="appId",dataType="String",required=true,value="应用ID"),
		 @ApiImplicitParam(paramType="query",name="group",dataType="String",required=true,value="对应配置中心配置上传组名(如:public,private等)"),
		 @ApiImplicitParam(paramType="query",name="fileName",dataType="String",required=false,value="上传文件名(覆盖上传必填)"),
		 @ApiImplicitParam(paramType="query",name="uploadDir",dataType="String",required=false,value="上传目录"),
		 @ApiImplicitParam(paramType="query",name="deleteAfterDays",dataType="Integer",required=false,value="上传多少天自动删除")
	})
	public @ResponseBody Map<String, Object> getUploadToken(HttpServletResponse response
			,@RequestParam(value="appId") String appId
			,@RequestParam(value="group") String group
			,@RequestParam(value="fileName",required = false) String fileName
			,@RequestParam(value="uploadDir") String uploadDir
			,@RequestParam(value="deleteAfterDays",required = false) Integer deleteAfterDays) {
		
		//TODO 验证 appid
		
//		if("redirect".equals(group)){
//			Map<String, Object> map = new HashMap<>();
//			map.put("uptoken", "12345556f");
//			map.put("uploadDir", uploadDir);
//			return map;
//		}
		UploadTokenParam param = new UploadTokenParam();
		param.setFileName(fileName);
		param.setUploadDir(uploadDir);
		param.setDeleteAfterDays(deleteAfterDays);
		Map<String, Object> map = FileSystemClient.getClient(group).createUploadToken(param);
		map.put("appId", appId);
		return map;
	}
 
Example #2
Source File: QcloudProvider.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> createUploadToken(UploadTokenParam param) {
	Map<String, Object> config = new TreeMap<String, Object>();

	// 替换为您的 SecretId
	config.put("SecretId", "AKIDHTVVaVR6e3");
	// 替换为您的 SecretKey
	config.put("SecretKey", "PdkhT9e2rZCfy6");

	// 临时密钥有效时长,单位是秒,默认1800秒,最长可设定有效期为7200秒
	config.put("durationSeconds", 1800);

	// 换成您的 bucket
	config.put("bucket", "examplebucket-1250000000");
	// 换成 bucket 所在地区
	config.put("region", "ap-guangzhou");
	config.put("allowPrefix", "a.jpg");

	// 密钥的权限列表。简单上传、表单上传和分片上传需要以下的权限,其他权限列表请看
	// https://cloud.tencent.com/document/product/436/31923
	String[] allowActions = new String[] {
			// 简单上传
			"name/cos:PutObject",
			// 表单上传、小程序上传
			"name/cos:PostObject",
			// 分片上传
			"name/cos:InitiateMultipartUpload", "name/cos:ListMultipartUploads", "name/cos:ListParts",
			"name/cos:UploadPart", "name/cos:CompleteMultipartUpload" };
	config.put("allowActions", allowActions);

	//JSONObject credential = CosStsClient.getCredential(config);
	// 成功返回临时密钥信息,如下打印密钥信息
	return null;
}
 
Example #3
Source File: QiniuProvider.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> createUploadToken(UploadTokenParam param) {
	
	if(StringUtils.isNotBlank(param.getCallbackUrl())){
		if(StringUtils.isBlank(param.getCallbackBody())){
			param.setCallbackBody(DEFAULT_CALLBACK_BODY);
		}
		if(StringUtils.isBlank(param.getCallbackHost())){
			param.setCallbackHost(host);
		}
	}
	
	Map<String, Object> result = new HashMap<>();
	StringMap policy = new StringMap();
	policy.putNotNull(policyFields[0], param.getCallbackUrl());
	policy.putNotNull(policyFields[1], param.getCallbackBody());
	policy.putNotNull(policyFields[2], param.getCallbackHost());
	policy.putNotNull(policyFields[3], param.getCallbackBodyType());
	policy.putNotNull(policyFields[4], param.getFileType());
	policy.putNotNull(policyFields[5], param.getFileKey());
	policy.putNotNull(policyFields[6], param.getMimeLimit());
	policy.putNotNull(policyFields[7], param.getFsizeMin());
	policy.putNotNull(policyFields[8], param.getFsizeMax());
	policy.putNotNull(policyFields[9], param.getDeleteAfterDays());

	String token = auth.uploadToken(bucketName, param.getFileKey(), param.getExpires(), policy, true);
	result.put("uptoken", token);
	result.put("host", this.urlprefix);
	result.put("dir", param.getUploadDir());
	
	return result;
}
 
Example #4
Source File: AliyunOssService.java    From feiqu-opensource with Apache License 2.0 4 votes vote down vote up
/**
	 * 签名生成
	 * @return
	 */
	public JSONObject policy() {

		FileSystemClient fileSystemClient = FileSystemClient.getClient("aliyun");
		UploadTokenParam uploadTokenParam = new UploadTokenParam();
		// 存储目录
		String dir = DateUtil.format(new Date(),"yyyy/MM/dd");
		uploadTokenParam.setUploadDir(dir);
		// 签名有效期
		long expireEndTime = CommonConstant.ALIYUN_OSS_EXPIRE;
		uploadTokenParam.setExpires(expireEndTime);
		uploadTokenParam.setCallbackUrl(CommonConstant.ALIYUN_OSS_CALLBACK);
		uploadTokenParam.setFsizeMax(CommonConstant.ALIYUN_OSS_MAX_SIZE * 1024 * 1024);
		Map<String, Object> map =  fileSystemClient.createUploadToken(uploadTokenParam);
// 提交节点
		String action = "http://" + CommonConstant.ALIYUN_OSS_BUCKET_NAME + "." + CommonConstant.ALIYUN_OSS_ENDPOINT;
		map.put("action",action);
		map.put("myDomain", CommonConstant.ALIOSS_URL_PREFIX);
		JSONObject result = new JSONObject(map);
		return result;

		/*Date expiration = new Date(expireEndTime);
		// 文件大小
		long maxSize = CommonConstant.ALIYUN_OSS_MAX_SIZE * 1024 * 1024;
		// 回调
		JSONObject callback = new JSONObject();
		callback.put("callbackUrl", CommonConstant.ALIYUN_OSS_CALLBACK);
		callback.put("callbackBody", "filename=${object}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}");
		callback.put("callbackBodyType", "application/x-www-form-urlencoded");
		// 提交节点
		String action = "http://" + CommonConstant.ALIYUN_OSS_BUCKET_NAME + "." + CommonConstant.ALIYUN_OSS_ENDPOINT;
		try {
			PolicyConditions policyConds = new PolicyConditions();
			policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, maxSize);
			policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
			String postPolicy = aliyunOssClient.generatePostPolicy(expiration, policyConds);
			byte[] binaryData = postPolicy.getBytes("utf-8");
			String policy = BinaryUtil.toBase64String(binaryData);
			String signature = aliyunOssClient.calculatePostSignature(postPolicy);
			String callbackData = BinaryUtil.toBase64String(callback.toString().getBytes("utf-8"));
			// 返回结果
			result.put("OSSAccessKeyId", aliyunOssClient.getCredentialsProvider().getCredentials().getAccessKeyId());
			result.put("policy", policy);
			result.put("signature", signature);
			result.put("dir", dir);
			result.put("callback", callbackData);
			result.put("myDomain", CommonConstant.ALIOSS_URL_PREFIX);
			result.put("action", action);
		} catch (Exception e) {
			LOGGER.error("签名生成失败", e);
		}
		return result;*/
	}
 
Example #5
Source File: FSProviderSpringFacade.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public Map<String, Object> createUploadToken(UploadTokenParam param) {
	return fsProvider.createUploadToken(param);
}
 
Example #6
Source File: FdfsProvider.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> createUploadToken(UploadTokenParam param) {
	return null;
}
 
Example #7
Source File: AliyunossProvider.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> createUploadToken(UploadTokenParam param) {
	
	Map<String, Object> result = new HashMap<>();
	
	PolicyConditions policyConds = new PolicyConditions();
	if(param.getFsizeMin() != null && param.getFsizeMax() != null){			
		policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, param.getFsizeMin(), param.getFsizeMax());
	}else{
		policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000);
	}
	if(param.getUploadDir() != null){			
		policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, param.getUploadDir());
	}
       
	if(StringUtils.isBlank(param.getCallbackHost())){
		param.setCallbackHost(host);
	}
	
	if(StringUtils.isBlank(param.getCallbackBody())){
		param.setCallbackBody(DEFAULT_CALLBACK_BODY);
	}
	
	Date expire = DateUtils.addSeconds(new Date(), (int)param.getExpires());
	String policy = ossClient.generatePostPolicy(expire, policyConds);
       String policyBase64 = null;
       String callbackBase64 = null;
       try {
       	policyBase64 = BinaryUtil.toBase64String(policy.getBytes(StandardCharsets.UTF_8.name()));
       	String callbackJson = param.getCallbackRuleAsJson();
       	if(callbackJson != null){
       		callbackBase64 = BinaryUtil.toBase64String(callbackJson.getBytes(StandardCharsets.UTF_8.name()));
       	}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	String signature = ossClient.calculatePostSignature(policy);
	
	result.put("OSSAccessKeyId", accessKeyId);
	result.put("policy", policyBase64);
	result.put("signature", signature);
	result.put("host", this.urlprefix);
	result.put("dir", param.getUploadDir());
	result.put("expire", String.valueOf(expire.getTime()));
	if(callbackBase64 != null){
		result.put("callback", callbackBase64);
	}
	return result;
}
 
Example #8
Source File: FileSystemClientTest.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	UploadTokenParam param = new UploadTokenParam();
	Map<String, Object> token = FileSystemClient.getClient("xxxx2").createUploadToken(param);
	
	System.out.println(token);
}