|
@@ -37,12 +37,12 @@ public class AliyunUpload {
|
|
* */
|
|
* */
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
public static String uploadForByte(byte[] content,String savePath,String fileName){
|
|
public static String uploadForByte(byte[] content,String savePath,String fileName){
|
|
- OSSClient ossClient = new OSSClient(AliyunConfig.endpoint, AliyunConfig.accessKeyId,AliyunConfig.accessKeySecret);
|
|
|
|
|
|
+ OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
|
|
String url = "";
|
|
String url = "";
|
|
try {
|
|
try {
|
|
String key = savePath+fileName;
|
|
String key = savePath+fileName;
|
|
- ossClient.putObject(AliyunConfig.bucketName, key, new ByteArrayInputStream(content));
|
|
|
|
- url = AliyunConfig.visitPath+"/"+savePath+URLEncoder.encode(fileName);
|
|
|
|
|
|
+ ossClient.putObject(AliyunConfig.BUCKETNAME, key, new ByteArrayInputStream(content));
|
|
|
|
+ url = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
return null;
|
|
return null;
|
|
@@ -60,12 +60,12 @@ public class AliyunUpload {
|
|
* */
|
|
* */
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
public static String uploadForLocalFile(File file, String savePath,String fileName){
|
|
public static String uploadForLocalFile(File file, String savePath,String fileName){
|
|
- OSSClient ossClient = new OSSClient(AliyunConfig.endpoint, AliyunConfig.accessKeyId,AliyunConfig.accessKeySecret);
|
|
|
|
|
|
+ OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
|
|
String url = "";
|
|
String url = "";
|
|
try {
|
|
try {
|
|
String key = savePath+fileName;
|
|
String key = savePath+fileName;
|
|
- ossClient.putObject(AliyunConfig.bucketName, key, file);
|
|
|
|
- url = AliyunConfig.visitPath+"/"+savePath+URLEncoder.encode(fileName);
|
|
|
|
|
|
+ ossClient.putObject(AliyunConfig.BUCKETNAME, key, file);
|
|
|
|
+ url = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
//e.printStackTrace();
|
|
//e.printStackTrace();
|
|
return null;
|
|
return null;
|
|
@@ -83,12 +83,12 @@ public class AliyunUpload {
|
|
* */
|
|
* */
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
public static String uploadForStream(InputStream is, String savePath,String fileName){
|
|
public static String uploadForStream(InputStream is, String savePath,String fileName){
|
|
- OSSClient ossClient = new OSSClient(AliyunConfig.endpoint, AliyunConfig.accessKeyId,AliyunConfig.accessKeySecret);
|
|
|
|
|
|
+ OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
|
|
String url = "";
|
|
String url = "";
|
|
try {
|
|
try {
|
|
String key = savePath+fileName;
|
|
String key = savePath+fileName;
|
|
- ossClient.putObject(AliyunConfig.bucketName, key, is);
|
|
|
|
- url = AliyunConfig.visitPath+"/"+savePath+URLEncoder.encode(fileName);
|
|
|
|
|
|
+ ossClient.putObject(AliyunConfig.BUCKETNAME, key, is);
|
|
|
|
+ url = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
return null;
|
|
return null;
|
|
@@ -106,13 +106,13 @@ public class AliyunUpload {
|
|
* */
|
|
* */
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
public static String uploadForUrl(String url, String savePath,String fileName){
|
|
public static String uploadForUrl(String url, String savePath,String fileName){
|
|
- OSSClient ossClient = new OSSClient(AliyunConfig.endpoint, AliyunConfig.accessKeyId,AliyunConfig.accessKeySecret);
|
|
|
|
|
|
+ OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
|
|
String path = "";
|
|
String path = "";
|
|
try {
|
|
try {
|
|
String key = savePath+fileName;
|
|
String key = savePath+fileName;
|
|
InputStream inputStream = new URL(url).openStream();
|
|
InputStream inputStream = new URL(url).openStream();
|
|
- ossClient.putObject(AliyunConfig.bucketName, key, inputStream);
|
|
|
|
- path = AliyunConfig.visitPath+"/"+savePath+URLEncoder.encode(fileName);
|
|
|
|
|
|
+ ossClient.putObject(AliyunConfig.BUCKETNAME, key, inputStream);
|
|
|
|
+ path = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
return null;
|
|
return null;
|
|
@@ -130,12 +130,12 @@ public class AliyunUpload {
|
|
* */
|
|
* */
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
public static String uploadForString(String content, String savePath,String fileName){
|
|
public static String uploadForString(String content, String savePath,String fileName){
|
|
- OSSClient ossClient = new OSSClient(AliyunConfig.endpoint, AliyunConfig.accessKeyId,AliyunConfig.accessKeySecret);
|
|
|
|
|
|
+ OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
|
|
String path = "";
|
|
String path = "";
|
|
try {
|
|
try {
|
|
String key = savePath+fileName;
|
|
String key = savePath+fileName;
|
|
- ossClient.putObject(AliyunConfig.bucketName, key, new ByteArrayInputStream(content.getBytes()));
|
|
|
|
- path = AliyunConfig.visitPath+"/"+savePath+URLEncoder.encode(fileName);
|
|
|
|
|
|
+ ossClient.putObject(AliyunConfig.BUCKETNAME, key, new ByteArrayInputStream(content.getBytes()));
|
|
|
|
+ path = AliyunConfig.VISITPATH+"/"+savePath+URLEncoder.encode(fileName);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
return null;
|
|
return null;
|
|
@@ -167,7 +167,7 @@ public class AliyunUpload {
|
|
//System.out.println(fileName);
|
|
//System.out.println(fileName);
|
|
InputStream inputStream = new URL(url).openStream();
|
|
InputStream inputStream = new URL(url).openStream();
|
|
ossClient.putObject("lnfile", key, inputStream);
|
|
ossClient.putObject("lnfile", key, inputStream);
|
|
- path = AliyunConfig.visitPath+key;
|
|
|
|
|
|
+ path = AliyunConfig.VISITPATH+key;
|
|
System.out.println(path);
|
|
System.out.println(path);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -207,11 +207,11 @@ public class AliyunUpload {
|
|
* */
|
|
* */
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
public static String uploadForGzptStream(InputStream is, String savePath,String fileName){
|
|
public static String uploadForGzptStream(InputStream is, String savePath,String fileName){
|
|
- OSSClient ossClient = new OSSClient(AliyunConfig.endpoint, AliyunConfig.accessKeyId,AliyunConfig.accessKeySecret);
|
|
|
|
|
|
+ OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
|
|
String url = "";
|
|
String url = "";
|
|
try {
|
|
try {
|
|
String key = savePath+fileName;
|
|
String key = savePath+fileName;
|
|
- ossClient.putObject(AliyunConfig.bucketName, key, is);
|
|
|
|
|
|
+ ossClient.putObject(AliyunConfig.BUCKETNAME, key, is);
|
|
url = savePath+URLEncoder.encode(fileName);
|
|
url = savePath+URLEncoder.encode(fileName);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -228,15 +228,15 @@ public class AliyunUpload {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static boolean deleteObject(String filePath) {
|
|
public static boolean deleteObject(String filePath) {
|
|
- OSSClient ossClient = new OSSClient(AliyunConfig.endpoint, AliyunConfig.accessKeyId,AliyunConfig.accessKeySecret);
|
|
|
|
|
|
+ OSSClient ossClient = new OSSClient(AliyunConfig.ENDPOINT, AliyunConfig.ACCESSKEYID,AliyunConfig.ACCESSKEYSECRET);
|
|
|
|
|
|
try {
|
|
try {
|
|
- boolean exist = ossClient.doesObjectExist(AliyunConfig.bucketName,filePath);
|
|
|
|
|
|
+ boolean exist = ossClient.doesObjectExist(AliyunConfig.BUCKETNAME,filePath);
|
|
if (!exist) {
|
|
if (!exist) {
|
|
System.out.println("文件不存在");
|
|
System.out.println("文件不存在");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- ossClient.deleteObject(AliyunConfig.bucketName,filePath);
|
|
|
|
|
|
+ ossClient.deleteObject(AliyunConfig.BUCKETNAME,filePath);
|
|
|
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|