parent
9b1bf4e9d6
commit
b7a8f7cd55
@ -0,0 +1,40 @@
|
|||||||
|
package gostorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Jdcloud 京东云
|
||||||
|
type Jdcloud struct {
|
||||||
|
AccessKey string
|
||||||
|
SecretKey string
|
||||||
|
Endpoint *string
|
||||||
|
Regions *string
|
||||||
|
BucketName string
|
||||||
|
error error // 错误信息
|
||||||
|
client *s3.S3 // 驱动
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewJdcloud 初始化
|
||||||
|
// https://docs.jdcloud.com/cn/object-storage-service/sdk-go
|
||||||
|
func NewJdcloud(accessKey string, secretKey string, endpoint *string, regions *string, bucketName string) *Jdcloud {
|
||||||
|
app := &Jdcloud{AccessKey: accessKey, SecretKey: secretKey, Endpoint: endpoint, Regions: regions, BucketName: bucketName}
|
||||||
|
reds := credentials.NewStaticCredentials(accessKey, secretKey, "")
|
||||||
|
_, app.error = reds.Get()
|
||||||
|
app.client = s3.New(session.New(&aws.Config{
|
||||||
|
Region: app.Regions,
|
||||||
|
Endpoint: app.Endpoint,
|
||||||
|
DisableSSL: aws.Bool(false),
|
||||||
|
Credentials: reds,
|
||||||
|
}))
|
||||||
|
return app
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucket 存储空间
|
||||||
|
func (c *Jdcloud) Bucket(name string) *Jdcloud {
|
||||||
|
c.BucketName = name
|
||||||
|
return c
|
||||||
|
}
|
@ -1 +1,61 @@
|
|||||||
package gostorage
|
package gostorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"github.com/ks3sdklib/aws-sdk-go/aws"
|
||||||
|
"github.com/ks3sdklib/aws-sdk-go/aws/credentials"
|
||||||
|
"github.com/ks3sdklib/aws-sdk-go/service/s3"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ksyun 金山云
|
||||||
|
type Ksyun struct {
|
||||||
|
AccessKey string
|
||||||
|
SecretKey string
|
||||||
|
Endpoint string
|
||||||
|
Regions string
|
||||||
|
BucketName string
|
||||||
|
client *s3.S3 // 驱动
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewKsyun 初始化
|
||||||
|
// https://docs.ksyun.com/documents/40487
|
||||||
|
func NewKsyun(accessKey string, secretKey string, endpoint string, regions string, bucketName string) *Ksyun {
|
||||||
|
app := &Ksyun{AccessKey: accessKey, SecretKey: secretKey, Endpoint: endpoint, Regions: regions, BucketName: bucketName}
|
||||||
|
var cre = credentials.NewStaticCredentials(accessKey, secretKey, "")
|
||||||
|
app.client = s3.New(&aws.Config{
|
||||||
|
Region: regions,
|
||||||
|
Credentials: cre,
|
||||||
|
Endpoint: endpoint,
|
||||||
|
})
|
||||||
|
return app
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucket 存储空间
|
||||||
|
func (c *Ksyun) Bucket(name string) *Ksyun {
|
||||||
|
c.BucketName = name
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutObject 上传文件流
|
||||||
|
// @param file 文件流
|
||||||
|
// @param filePath 文件路径
|
||||||
|
// @param fileName 文件名称
|
||||||
|
func (c *Ksyun) PutObject(file io.Reader, filePath, fileName, acl string) (resp FileInfo, err error) {
|
||||||
|
objectKey := filePath
|
||||||
|
if fileName != "" {
|
||||||
|
objectKey = filePath + "/" + fileName
|
||||||
|
}
|
||||||
|
params := &s3.PutObjectInput{
|
||||||
|
Bucket: aws.String(c.BucketName),
|
||||||
|
Key: aws.String(objectKey),
|
||||||
|
ACL: aws.String(acl),
|
||||||
|
Body: bytes.NewReader(file),
|
||||||
|
ContentType: aws.String("application/octet-stream"),
|
||||||
|
}
|
||||||
|
_, err = c.client.PutObject(params)
|
||||||
|
resp.Path = filePath
|
||||||
|
resp.Name = fileName
|
||||||
|
resp.Url = objectKey
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -1 +1,64 @@
|
|||||||
package gostorage
|
package gostorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/qiniu/go-sdk/v7/auth/qbox"
|
||||||
|
"github.com/qiniu/go-sdk/v7/storage"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Qiniu 七牛云
|
||||||
|
type Qiniu struct {
|
||||||
|
AccessKey string
|
||||||
|
SecretKey string
|
||||||
|
BucketName string
|
||||||
|
client *qbox.Mac // 驱动
|
||||||
|
bucket *storage.PutPolicy // 存储空间
|
||||||
|
upToken string // 上传凭证
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewQiniu 初始化
|
||||||
|
// https://developer.qiniu.com/kodo/1238/go
|
||||||
|
func NewQiniu(accessKey string, secretKey string, bucketName string) *Qiniu {
|
||||||
|
app := &Qiniu{AccessKey: accessKey, SecretKey: secretKey, BucketName: bucketName}
|
||||||
|
app.client = qbox.NewMac(accessKey, secretKey)
|
||||||
|
app.bucket.Scope = bucketName
|
||||||
|
app.upToken = app.bucket.UploadToken(app.client)
|
||||||
|
return app
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucket 存储空间
|
||||||
|
func (c *Qiniu) Bucket(name string) *Qiniu {
|
||||||
|
c.BucketName = name
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutObject 上传文件流
|
||||||
|
// @param file 文件流
|
||||||
|
// @param filePath 文件路径
|
||||||
|
// @param fileName 文件名称
|
||||||
|
func (c *Qiniu) PutObject(file io.Reader, filePath, fileName, acl string) (resp FileInfo, err error) {
|
||||||
|
objectKey := filePath
|
||||||
|
if fileName != "" {
|
||||||
|
objectKey = filePath + "/" + fileName
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := storage.Config{}
|
||||||
|
// 空间对应的机房
|
||||||
|
cfg.Zone = &storage.ZoneHuanan
|
||||||
|
// 是否使用https域名
|
||||||
|
cfg.UseHTTPS = true
|
||||||
|
// 上传是否使用CDN上传加速
|
||||||
|
cfg.UseCdnDomains = false
|
||||||
|
|
||||||
|
formUploader := storage.NewFormUploader(&cfg)
|
||||||
|
ret := storage.PutRet{}
|
||||||
|
putExtra := storage.PutExtra{}
|
||||||
|
|
||||||
|
err = formUploader.Put(context.Background(), &ret, c.upToken, objectKey, file, -1, &putExtra)
|
||||||
|
|
||||||
|
resp.Path = filePath
|
||||||
|
resp.Name = fileName
|
||||||
|
resp.Url = objectKey
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -1 +1,51 @@
|
|||||||
package gostorage
|
package gostorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/upyun/go-sdk/v3/upyun"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Upyun 又拍云
|
||||||
|
type Upyun struct {
|
||||||
|
Operator string
|
||||||
|
Password string
|
||||||
|
BucketName string
|
||||||
|
client *upyun.UpYun // 驱动
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUpyun 初始化
|
||||||
|
// https://github.com/upyun/go-sdk
|
||||||
|
func NewUpyun(operator string, password string, bucketName string) *Upyun {
|
||||||
|
app := &Upyun{Operator: operator, Password: password, BucketName: bucketName}
|
||||||
|
app.client = upyun.NewUpYun(&upyun.UpYunConfig{
|
||||||
|
Bucket: bucketName,
|
||||||
|
Operator: operator,
|
||||||
|
Password: password,
|
||||||
|
})
|
||||||
|
return app
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucket 存储空间
|
||||||
|
func (c *Upyun) Bucket(name string) *Upyun {
|
||||||
|
c.BucketName = name
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutObject 上传文件流
|
||||||
|
// @param file 文件流
|
||||||
|
// @param filePath 文件路径
|
||||||
|
// @param fileName 文件名称
|
||||||
|
func (c *Upyun) PutObject(file io.Reader, filePath, fileName, acl string) (resp FileInfo, err error) {
|
||||||
|
objectKey := filePath
|
||||||
|
if fileName != "" {
|
||||||
|
objectKey = filePath + "/" + fileName
|
||||||
|
}
|
||||||
|
err = c.client.Put(&upyun.PutObjectConfig{
|
||||||
|
Path: "/demo.log",
|
||||||
|
LocalPath: "/tmp/upload",
|
||||||
|
})
|
||||||
|
resp.Path = filePath
|
||||||
|
resp.Name = fileName
|
||||||
|
resp.Url = objectKey
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
Reference in new issue