Commit 3a34c282 by 王栋源

wdy

parent a5eb5402
......@@ -20,6 +20,7 @@ public class uploadossapi {
System.out.println(a);
JSONObject jsonObject = JSONObject.parseObject(a);
String ossurl=jsonObject.getString("ossurl");
String filedir=jsonObject.getString("filedir");
String objectName=jsonObject.getString("objectName");
String encodePolicy=jsonObject.getString("encodePolicy");
String signature=jsonObject.getString("signature");
......@@ -27,7 +28,7 @@ public class uploadossapi {
String accessKeyId=jsonObject.getString("accessKeyId");
String bucketName=jsonObject.getString("bucketName");
utilupload utilupload=new utilupload();
utilupload.doUpload(ossurl,endpoint,accessKeyId,bucketName,objectName,encodePolicy,signature);
utilupload.doUpload(ossurl,endpoint,accessKeyId,bucketName,filedir,objectName,encodePolicy,signature);
return true;
} catch (Exception e) {
return false;
......@@ -41,8 +42,8 @@ public class uploadossapi {
public void helloworlds(){
try {
System.out.println("fdfd");
testuploadossapi testuploadossapi=new testuploadossapi();
testuploadossapi.doUpload();
// testuploadossapi testuploadossapi=new testuploadossapi();
// testuploadossapi.doUpload();
} catch (Exception e) {
System.err.println("Send post request exception: " + e);
}
......
......@@ -17,27 +17,26 @@ import org.apache.commons.io.FileUtils;
public class utilupload {
// 上传文件
private String localFilePath = "";
// Endpoint以杭州为例,其它Region请按实际情况填写。
private String localFilePath = "/tmp/temporaryfile.jpg";
// Endpoint以杭州为例,其它Region请按实际情况填写。
private String endpoint = "http://oss-cn-beijing.aliyuncs.com";
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
private String accessKeyId = "hObpgEXoca42qH3V";
// 存储空间名称
private String bucketName = "trade-mark-user-upload";
// 文件名称
// 文件名称
private String objectName = "";
public void doUpload(String ossurl,String endpoint1,String accessKeyId1,String bucketName1,String objectName,String encodePolicy,String signature) throws Exception {
public void doUpload(String ossurl,String endpoint,String accessKeyId,String bucketName,String filedir,String objectName,String encodePolicy,String signature) throws Exception {
URL httpurl = new URL(ossurl);
File file = new File("F:\\swch\\commons-io-2.6\\aaa.jpg");
File file = new File("/tmp/temporaryfile.jpg");
FileUtils.copyURLToFile(httpurl, file);
this.objectName="30039057/icon/1585794705963/"+objectName;
// this.endpoint=endpoint;
// this.accessKeyId=accessKeyId;
// this.bucketName=bucketName;
this.localFilePath="F:\\swch\\commons-io-2.6\\aaa.jpg";
this.objectName=filedir+objectName;
this.endpoint=endpoint;
this.accessKeyId=accessKeyId;
this.bucketName=bucketName;
// 在URL中添加存储空间名称,添加后URL如下:http://yourBucketName.oss-cn-hangzhou.aliyuncs.com
String urlStr = endpoint.replace("http://", "http://" + bucketName + ".");
// 表单Map。
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment