/**
* *
[font='Courier New']上传文件到阿里云
OSS
* @param
file
[font='Courier New']需要上传的文件
[font='Courier New']
* @param
toFileName
[font='Courier New']上传上去的文件名
[font='Courier New']
* @param
dirName
[font='Courier New']上传到的文件夹名
[font='Courier New']
* @return
[font='Courier New']文件访问地址
[font='Courier New']
*/
public String
upload(File file
,String toFileName
,String dirName ){
String fileUrl =
""
;
try {
OSSClient client =
createBucket()
;
LOG.info(
"
[font='Courier New']正在上传
...")
;
uploadFile(client
,
bucketName
, dirName+
"/"+toFileName
,file )
;
LOG.info(
"
[font='Courier New']上传成功。。
.")
;
fileUrl = BaseConst.
imgAddress+
"/"+dirName+
"/"+toFileName
;
LOG.info(
"
[font='Courier New']上传文件
URL:"+fileUrl)
;
return fileUrl
;
}
catch(Exception e) {
LOG.error(
" UPLOAD FILE ERROR !"
,e)
;
}
return null;
}
//上传
String imagePath =
"F:
\\
testDoc
\\
test-2.pdf"
;
File file=
new File(imagePath)
;
String url=uploadService.upload(file
,
"test-2.pdf"
,
"test/template")
;
网页中打开如下: