Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cd46a45aa |
52
file.go
52
file.go
@@ -1,9 +1,8 @@
|
|||||||
package go_aliyun_oss
|
package go_aliyun_oss
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"os"
|
"os"
|
||||||
@@ -21,31 +20,34 @@ type OssFile struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OssFileInterface interface {
|
type OssFileInterface interface {
|
||||||
FileTypeTransForm() (*OssFile, error)
|
FileTypeTransForm() (*OssFile,error)
|
||||||
GetFileType() *OssFile
|
GetFileType() *OssFile
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileTypeTransForm file type transform
|
// @method: FileTypeTransForm
|
||||||
// @title 文件类型转换
|
// @description: 文件类型转换
|
||||||
func (ossFile *OssFile) FileTypeTransForm() (*OssFile, error) {
|
// @author: mr.x 2021-06-19 00:28:46
|
||||||
|
// @return: *OssFile
|
||||||
|
// @return: error
|
||||||
|
func (ossFile *OssFile) FileTypeTransForm() (*OssFile,error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch ossFile.File.(type) {
|
switch ossFile.File.(type) {
|
||||||
case *os.File:
|
case *os.File:
|
||||||
|
|
||||||
ossFile.FileByte, err = ioutil.ReadAll(ossFile.File.(*os.File))
|
ossFile.FileByte,err = ioutil.ReadAll(ossFile.File.(*os.File))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("read os type file failed:" + err.Error())
|
panic("read os type file failed:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ossFile.FileOldName = filepath.Split(ossFile.File.(*os.File).Name())
|
_,ossFile.FileOldName = filepath.Split(ossFile.File.(*os.File).Name())
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case *multipart.FileHeader:
|
case *multipart.FileHeader:
|
||||||
|
|
||||||
fileResources, err := ossFile.File.(*multipart.FileHeader).Open()
|
fileResources,err := ossFile.File.(*multipart.FileHeader).Open()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("open multipart file failed:" + err.Error())
|
panic("open multipart file failed:" + err.Error())
|
||||||
@@ -53,10 +55,10 @@ func (ossFile *OssFile) FileTypeTransForm() (*OssFile, error) {
|
|||||||
|
|
||||||
defer fileResources.Close()
|
defer fileResources.Close()
|
||||||
|
|
||||||
ossFile.FileByte, err = ioutil.ReadAll(fileResources)
|
ossFile.FileByte,err = ioutil.ReadAll(fileResources)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("read multipart file failed:" + err.Error())
|
panic("read multipart file failed:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
ossFile.FileOldName = ossFile.File.(*multipart.FileHeader).Filename
|
ossFile.FileOldName = ossFile.File.(*multipart.FileHeader).Filename
|
||||||
@@ -64,17 +66,17 @@ func (ossFile *OssFile) FileTypeTransForm() (*OssFile, error) {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case string:
|
case string:
|
||||||
newFile, err := os.Open(ossFile.File.(string))
|
newFile,err := os.Open(ossFile.File.(string))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("open file path failed:" + err.Error())
|
panic("open file path failed:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
defer newFile.Close()
|
defer newFile.Close()
|
||||||
|
|
||||||
ossFile.FileByte, err = ioutil.ReadAll(newFile)
|
ossFile.FileByte,err = ioutil.ReadAll(newFile)
|
||||||
|
|
||||||
_, ossFile.FileOldName = filepath.Split(newFile.Name())
|
_,ossFile.FileOldName = filepath.Split(newFile.Name())
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -84,31 +86,33 @@ func (ossFile *OssFile) FileTypeTransForm() (*OssFile, error) {
|
|||||||
|
|
||||||
//判断是否指定了文件的类型 如果没有指定默认为png格式
|
//判断是否指定了文件的类型 如果没有指定默认为png格式
|
||||||
if ossFile.FileType == "" || len(ossFile.FileType) <= 0 {
|
if ossFile.FileType == "" || len(ossFile.FileType) <= 0 {
|
||||||
ossFile.FileOldName = uuid.NewString() + ".png"
|
ossFile.FileOldName = uuid.NewV4().String() + ".png"
|
||||||
} else {
|
} else {
|
||||||
ossFile.FileOldName = uuid.NewString() + ossFile.FileType
|
ossFile.FileOldName = uuid.NewV4().String() + ossFile.FileType
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Println(reflect.TypeOf(ossFile.File))
|
fmt.Println(reflect.TypeOf(ossFile.File))
|
||||||
return nil, errors.New("file type is not support")
|
panic("file type is not support" )
|
||||||
}
|
}
|
||||||
|
|
||||||
ossFile.GetFileType()
|
ossFile.GetFileType()
|
||||||
|
|
||||||
return ossFile, nil
|
return ossFile,nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFileType split file type and generate file name
|
// @method: GetFileType
|
||||||
// 截取文件类型
|
// @description: 截取文件类型
|
||||||
|
// @author: mr.x 2021-06-19 00:28:52
|
||||||
|
// @return: *OssFile
|
||||||
func (ossFile *OssFile) GetFileType() *OssFile {
|
func (ossFile *OssFile) GetFileType() *OssFile {
|
||||||
|
|
||||||
// 当没有传递文件类型时去文件名中截取出文件类型
|
// 当没有传递文件类型时去文件名中截取出文件类型
|
||||||
if ossFile.FileType == "" || len(ossFile.FileType) <= 0 {
|
if ossFile.FileType == "" || len(ossFile.FileType) <= 0 {
|
||||||
//from oldFileName split file type
|
//from oldFileName split file type
|
||||||
fileTypeSufIndex := strings.Index(ossFile.FileOldName, ".")
|
fileTypeSufIndex := strings.Index(ossFile.FileOldName,".")
|
||||||
|
|
||||||
fileType := ossFile.FileOldName[fileTypeSufIndex:]
|
fileType := ossFile.FileOldName[fileTypeSufIndex:]
|
||||||
|
|
||||||
@@ -116,7 +120,7 @@ func (ossFile *OssFile) GetFileType() *OssFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//generate only file name
|
//generate only file name
|
||||||
ossFile.FileNewName = uuid.NewString() + ossFile.FileType
|
ossFile.FileNewName = uuid.NewV5(uuid.NewV4(),ossFile.FileOldName).String() + ossFile.FileType
|
||||||
|
|
||||||
return ossFile
|
return ossFile
|
||||||
}
|
}
|
||||||
4
go.mod
4
go.mod
@@ -3,9 +3,9 @@ module github.com/cowardmrx/go_aliyun_oss
|
|||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible
|
github.com/aliyun/aliyun-oss-go-sdk v2.1.5+incompatible
|
||||||
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
|
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/satori/go.uuid v1.2.0
|
||||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
|
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,11 +1,7 @@
|
|||||||
github.com/aliyun/aliyun-oss-go-sdk v2.1.5+incompatible h1:v5yDfjkRY/kOxu05gkh0/D/2wYxbTFCoTr3JqFI0FLE=
|
github.com/aliyun/aliyun-oss-go-sdk v2.1.5+incompatible h1:v5yDfjkRY/kOxu05gkh0/D/2wYxbTFCoTr3JqFI0FLE=
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v2.1.5+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
|
github.com/aliyun/aliyun-oss-go-sdk v2.1.5+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible h1:QoRMR0TCctLDqBCMyOu1eXdZyMw3F7uGA9qPn2J4+R8=
|
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
|
|
||||||
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
|
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
|
||||||
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
|
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
|
||||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ type AliOssConfigInterface interface {
|
|||||||
GetAccessibleUrl() string
|
GetAccessibleUrl() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckConfig check AliOssConfig value is exists
|
// @method: CheckConfig
|
||||||
|
// @description: 校验配置
|
||||||
|
// @author: mr.x 2021-06-19 00:28:17
|
||||||
func (coon *AliOssConfig) CheckConfig() {
|
func (coon *AliOssConfig) CheckConfig() {
|
||||||
//check endPoint
|
//check endPoint
|
||||||
if coon.EndPoint == "" || len(coon.EndPoint) <= 0 {
|
if coon.EndPoint == "" || len(coon.EndPoint) <= 0 {
|
||||||
@@ -49,8 +51,10 @@ func (coon *AliOssConfig) CheckConfig() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOssConnect en: create oss connect client
|
// @method: CreateOssConnect
|
||||||
//创建阿里云oss 链接客户端
|
// @description: 创建阿里云oss 链接客户端
|
||||||
|
// @author: mr.x 2021-06-19 00:28:10
|
||||||
|
// @return: *AliOssClient
|
||||||
func (coon *AliOssConfig) CreateOssConnect() *AliOssClient {
|
func (coon *AliOssConfig) CreateOssConnect() *AliOssClient {
|
||||||
//config check
|
//config check
|
||||||
coon.CheckConfig()
|
coon.CheckConfig()
|
||||||
@@ -82,8 +86,10 @@ func (coon *AliOssConfig) CreateOssConnect() *AliOssClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccessibleUrl get oss accessible url
|
// @method: GetAccessibleUrl
|
||||||
//拼接阿里云oss可访问地址
|
// @description: 拼接阿里云oss可访问地址
|
||||||
|
// @author: mr.x 2021-06-19 00:28:02
|
||||||
|
// @return: string
|
||||||
func (coon *AliOssConfig) GetAccessibleUrl() string {
|
func (coon *AliOssConfig) GetAccessibleUrl() string {
|
||||||
var domain string
|
var domain string
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package go_aliyun_oss
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,11 +18,15 @@ type ossResponse struct {
|
|||||||
FileName string
|
FileName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put 推送文件到oss
|
|
||||||
// params: ossDir string `oss dir [要推送到的oss目录]` example: test/20201121/
|
// @method: Put
|
||||||
// params: file interface `upload file resource [文件资源]`
|
// @description: 推送文件到oss
|
||||||
// return string `oss file accessible uri [可访问地址]`
|
// @author: mr.x 2021-06-19 00:29:08
|
||||||
func (client *AliOssClient) Put(ossDir string, file interface{}, fileType string) (*ossResponse, error) {
|
// @param: ossDir string `[要推送到的oss目录]` example: test/20201121/
|
||||||
|
// @param: file interface{} `upload file resource [文件资源]`
|
||||||
|
// @param: fileType string `文件类型`
|
||||||
|
// @return: *ossResponse 返回oss可访问地址等
|
||||||
|
func (client *AliOssClient) Put(ossDir string, file interface{},fileType string) *ossResponse {
|
||||||
//file to []byte
|
//file to []byte
|
||||||
//文件转字节流
|
//文件转字节流
|
||||||
uploadFile := &OssFile{
|
uploadFile := &OssFile{
|
||||||
@@ -31,10 +34,10 @@ func (client *AliOssClient) Put(ossDir string, file interface{}, fileType string
|
|||||||
FileType: fileType,
|
FileType: fileType,
|
||||||
}
|
}
|
||||||
|
|
||||||
ossFile, err := uploadFile.FileTypeTransForm()
|
ossFile,err := uploadFile.FileTypeTransForm()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
panic("transfer file failed" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 最终的oss名称
|
// 最终的oss名称
|
||||||
@@ -56,10 +59,10 @@ func (client *AliOssClient) Put(ossDir string, file interface{}, fileType string
|
|||||||
}
|
}
|
||||||
|
|
||||||
//upload file to oss
|
//upload file to oss
|
||||||
err = client.Client.PutObject(ossPath, bytes.NewReader(ossFile.FileByte))
|
err = client.Client.PutObject(ossPath,bytes.NewReader(ossFile.FileByte))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("put file to oss failed:" + err.Error())
|
panic("put file to oss failed:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ossResponse{
|
return &ossResponse{
|
||||||
@@ -67,59 +70,67 @@ func (client *AliOssClient) Put(ossDir string, file interface{}, fileType string
|
|||||||
LongPath: client.Domain + "/" + ossPath,
|
LongPath: client.Domain + "/" + ossPath,
|
||||||
ShortPath: ossPath,
|
ShortPath: ossPath,
|
||||||
FileName: ossFileName,
|
FileName: ossFileName,
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasExists 校验文件是否已经存在
|
// @method: HasExists
|
||||||
// check file already exists in oss server
|
// @description: 校验文件是否已经存在
|
||||||
// params: ossFilePath string `file oss path [文件的oss的路径]`
|
// @author: mr.x 2021-06-19 00:30:21
|
||||||
func (client *AliOssClient) HasExists(ossFilePath string) (bool, error) {
|
// @param: ossFilePath string file oss path [文件的oss的路径]
|
||||||
|
// @return: bool
|
||||||
|
func (client *AliOssClient) HasExists(ossFilePath string) bool {
|
||||||
|
|
||||||
//oss check fun
|
//oss check fun
|
||||||
isExists, err := client.Client.IsObjectExist(ossFilePath)
|
isExists,err := client.Client.IsObjectExist(ossFilePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.New("check file in oss is exists failed:" + err.Error())
|
panic("check file in oss is exists failed:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return isExists, nil
|
return isExists
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件-单文件删除
|
// @method: Delete
|
||||||
// delete one file in oss
|
// @description: 删除文件-单文件删除
|
||||||
// params ossPath string `file oss path [文件的oss路径]`
|
// @author: mr.x 2021-06-19 00:30:40
|
||||||
// return bool
|
// @param: ossFilePath string oss 可访问路径
|
||||||
func (client *AliOssClient) Delete(ossFilePath string) (bool, error) {
|
// @return: bool true - 删除成功 | false - 删除失败
|
||||||
|
func (client *AliOssClient) Delete(ossFilePath string) bool {
|
||||||
|
|
||||||
//oss delete one file fun
|
//oss delete one file fun
|
||||||
err := client.Client.DeleteObject(ossFilePath)
|
err := client.Client.DeleteObject(ossFilePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.New("delete file " + ossFilePath + " failed:" + err.Error())
|
panic("delete file "+ ossFilePath +" failed:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteMore 删除文件-多文件删除
|
// @method: DeleteMore
|
||||||
// delete more file in oss
|
// @description: 删除文件-多文件删除
|
||||||
// params ossPath []string `file oss path array [文件的oss路径数组]`
|
// @author: mr.x 2021-06-19 00:30:56
|
||||||
// return bool
|
// @param: ossFilePath []string
|
||||||
func (client *AliOssClient) DeleteMore(ossFilePath []string) (bool, error) {
|
// @return: bool true - 批量删除成功 | false - 批量删除失败
|
||||||
|
func (client *AliOssClient) DeleteMore(ossFilePath []string) bool {
|
||||||
//oss delete more file fun
|
//oss delete more file fun
|
||||||
_, err := client.Client.DeleteObjects(ossFilePath)
|
_,err := client.Client.DeleteObjects(ossFilePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.New("delete more file in oss failed:" + err.Error())
|
panic("delete more file in oss failed:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTemporaryUrl 获取文件临时地址
|
|
||||||
// path string 文件路径
|
// @method: GetTemporaryUrl
|
||||||
// expireInSecond int64 多久后过期 单位: 秒,默认 60
|
// @description: 获取文件临时地址
|
||||||
func (client *AliOssClient) GetTemporaryUrl(path string, expireInSecond int64) (string, error) {
|
// @author: mr.x 2021-06-19 00:31:34
|
||||||
|
// @param: path string 文件路径【段路径】
|
||||||
|
// @param: expireInSecond int64 有效时间 秒 默认 60S
|
||||||
|
// @return: string
|
||||||
|
func (client *AliOssClient) GetTemporaryUrl(path string,expireInSecond int64) string {
|
||||||
|
|
||||||
var expireTime int64
|
var expireTime int64
|
||||||
|
|
||||||
@@ -129,12 +140,12 @@ func (client *AliOssClient) GetTemporaryUrl(path string, expireInSecond int64) (
|
|||||||
expireTime = expireInSecond
|
expireTime = expireInSecond
|
||||||
}
|
}
|
||||||
|
|
||||||
signUrl, err := client.Client.SignURL(path, oss.HTTPGet, expireTime)
|
signUrl,err := client.Client.SignURL(path,oss.HTTPGet,expireTime)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.New("generate sign url failed:" + err.Error())
|
panic("generate sign url failed:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return signUrl, nil
|
return signUrl
|
||||||
|
|
||||||
}
|
}
|
||||||
15
oss_test.go
15
oss_test.go
@@ -17,7 +17,7 @@ func TestPut(t *testing.T) {
|
|||||||
|
|
||||||
client := ossConfig.CreateOssConnect()
|
client := ossConfig.CreateOssConnect()
|
||||||
|
|
||||||
uri := client.Put("logo/", "./File/3HaqWaOzJWD86DDvZD9Pmn9VUEOBOBbuWackGOXb (2).jpeg", ".png")
|
uri := client.Put("logo/","./File/3HaqWaOzJWD86DDvZD9Pmn9VUEOBOBbuWackGOXb (2).jpeg",".png")
|
||||||
|
|
||||||
fmt.Println(uri)
|
fmt.Println(uri)
|
||||||
}
|
}
|
||||||
@@ -33,13 +33,15 @@ func TestPutBase64(t *testing.T) {
|
|||||||
client := ossConfig.CreateOssConnect()
|
client := ossConfig.CreateOssConnect()
|
||||||
|
|
||||||
// 读取base
|
// 读取base
|
||||||
file, _ := ioutil.ReadFile("./File/3HaqWaOzJWD86DDvZD9Pmn9VUEOBOBbuWackGOXb (2).jpeg")
|
file,_ := ioutil.ReadFile("./File/3HaqWaOzJWD86DDvZD9Pmn9VUEOBOBbuWackGOXb (2).jpeg")
|
||||||
|
|
||||||
|
|
||||||
fileStr := base64.StdEncoding.EncodeToString(file)
|
fileStr := base64.StdEncoding.EncodeToString(file)
|
||||||
|
|
||||||
bat, _ := base64.StdEncoding.DecodeString(fileStr)
|
bat,_ := base64.StdEncoding.DecodeString(fileStr)
|
||||||
|
|
||||||
uri := client.Put("logo/", bat, ".png")
|
|
||||||
|
uri := client.Put("logo/",bat,".png")
|
||||||
//
|
//
|
||||||
fmt.Println(uri)
|
fmt.Println(uri)
|
||||||
}
|
}
|
||||||
@@ -94,7 +96,7 @@ func TestAliOssClient_DeleteMore(t *testing.T) {
|
|||||||
|
|
||||||
func TestAliOssClient_GetTemporaryUrl(t *testing.T) {
|
func TestAliOssClient_GetTemporaryUrl(t *testing.T) {
|
||||||
ossConfig := &AliOssConfig{
|
ossConfig := &AliOssConfig{
|
||||||
EndPoint: "https://oss-cn-hangzhou.aliyuncs.com",
|
EndPoint: "",
|
||||||
AccessKeyId: "",
|
AccessKeyId: "",
|
||||||
AccessKeySecret: "",
|
AccessKeySecret: "",
|
||||||
BucketName: "",
|
BucketName: "",
|
||||||
@@ -102,7 +104,8 @@ func TestAliOssClient_GetTemporaryUrl(t *testing.T) {
|
|||||||
|
|
||||||
client := ossConfig.CreateOssConnect()
|
client := ossConfig.CreateOssConnect()
|
||||||
|
|
||||||
singUrl := client.GetTemporaryUrl("", 180)
|
singUrl := client.GetTemporaryUrl("logo/8497b913-2a79-58a1-984b-c25827f8212e.png",180)
|
||||||
|
|
||||||
fmt.Println(singUrl)
|
fmt.Println(singUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user