Explorar el Código

新增s3后端endpoint配置

hsun hace 1 año
padre
commit
14bad66a8c
Se han modificado 2 ficheros con 8 adiciones y 1 borrados
  1. 6 1
      services/aws_s3.go
  2. 2 0
      utils/config.go

+ 6 - 1
services/aws_s3.go

@@ -62,7 +62,12 @@ func (m *S3Oss) UploadFile(fileName, localFile, savePath string) (resourceUrl st
 		}
 	}()
 
-	endpoint := utils.S3Endpoint
+	// 默认使用后端这个, 这里有两个配置的原因是
+	// 前端上传跨域问题可能会使用反向代理来解决, 这样的话同一个endpoint就会导致一端正常另一端不正常
+	endpoint := utils.S3BackEndpoint
+	if endpoint == "" {
+		endpoint = utils.S3Endpoint
+	}
 	accessKey := utils.S3AccessKeyId
 	secretKey := utils.S3AccessKeySecret
 	region := utils.S3Region

+ 2 - 0
utils/config.go

@@ -216,6 +216,7 @@ var (
 // S3配置
 var (
 	S3Endpoint        string
+	S3BackEndpoint    string
 	S3BucketName      string
 	S3UploadDir       string
 	S3AccessKeyId     string
@@ -489,6 +490,7 @@ func init() {
 	// S3-OSS相关
 	{
 		S3Endpoint = config["s3_endpoint"]
+		S3BackEndpoint = config["s3_back_endpoint"]
 		S3BucketName = config["s3_bucket_name"]
 		S3Host = config["s3_host"]
 		S3AccessKeyId = config["s3_access_key_id"]