@@ -129,4 +129,58 @@ if err != nil {
129129fmt.Println (" content is :" , string (data))
130130```
131131
132+ ## 获取预签名上传URL
133+
134+ ``` go
135+ presignClient := s3.NewPresignClient (client, func (options *s3.PresignOptions ) {
136+ options.ClientOptions = []func (oo *s3.Options ){
137+ func (oo *s3.Options ) {
138+ oo.UsePathStyle = true
139+ },
140+ }
141+ })
142+ filename := " a/a.txt"
143+ putObjectInput := s3.PutObjectInput {
144+ Bucket : aws.String (config.Cfg .Oss .Bucket ),
145+ Key : aws.String (filename),
146+ }
147+ presignResult , err := presignClient.PresignPutObject (ctx, &putObjectInput, func (po *s3.PresignOptions ) {
148+ po.ClientOptions = []func (oo *s3.Options ){
149+ func (oo *s3.Options ) {
150+ oo.UsePathStyle = true
151+ },
152+ }
153+ po.Expires = uploadConfig.Expiration // 授权时效
154+ })
155+ if err != nil {
156+ return nil , errors.New (" Couldn't get presigned URL for GetObject" + err.Error ())
157+ }
158+ fmt.Printf (" 上传URL: %s \n " , presignResult.URL )
159+ ```
160+
161+ ## 获取预签名下载URL
162+
163+ ``` go
164+ presignClient := s3.NewPresignClient (client, func (options *s3.PresignOptions ) {
165+ options.ClientOptions = []func (oo *s3.Options ){
166+ func (oo *s3.Options ) {
167+ oo.UsePathStyle = true
168+ },
169+ }
170+ })
171+ filename := " a/a.txt"
172+ getObjectInput := s3.GetObjectInput {
173+ Bucket : aws.String (config.Cfg .Oss .Bucket ),
174+ Key : aws.String (filename),
175+ }
176+ presignResult , err := presignClient.PresignGetObject (ctx, &getObjectInput, func (po *s3.PresignOptions ) {
177+ // 授权时效
178+ po.Expires = expiration
179+ })
180+ if err != nil {
181+ return nil , errors.New (" Couldn't get presigned URL for GetObject,err: " + err.Error ())
182+ }
183+ fmt.Printf (" 访问URL: %s \n " , presignResult.URL )
184+ ```
185+
132186其他的使用,大家可以自行探索,如果借助 Vibe Coding,就更简单了!
0 commit comments