@@ -9,10 +9,13 @@ import (
99 "mime/multipart"
1010 "strings"
1111 "time"
12+ "regexp"
13+ "strconv"
1214
1315 "cloud.google.com/go/storage"
1416
1517 dbConfig "github.com/GDG-on-Campus-KHU/SDGP_team5_BE/db/config"
18+ coreUtil "github.com/GDG-on-Campus-KHU/SDGP_team5_BE/util"
1619)
1720
1821// GCS bucket์ ์์ฑ ๋
น์ ํ์ผ ์
๋ก๋ํ๊ณ file URL์ return
@@ -21,14 +24,26 @@ func UploadFileToGCS(file *multipart.FileHeader, userID string) (string, error)
2124 ctx := context .Background ()
2225 client := dbConfig .GCSClient
2326
27+ id , err := strconv .Atoi (userID )
28+ if err != nil {
29+ return "" , fmt .Errorf ("invalid userID format: %v" , err )
30+ }
31+
32+ user , err := coreUtil .GetUserByUserID (ctx , id )
33+ if err != nil {
34+ return "" , fmt .Errorf ("failed to get user info: %v" , err )
35+ }
36+
37+ username := regexp .MustCompile (`[^๊ฐ-ํฃa-zA-Z0-9_-]` ).ReplaceAllString (user .Name , "" )
38+
2439 // GCS bucket
2540 bucketName := "resq-upload-bucket"
2641 bucket := client .Bucket (bucketName )
2742
2843 // unique filename generation rule
2944 ext := strings .ToLower (file .Filename [strings .LastIndex (file .Filename , "." ):])
30- timestamp := time .Now ().Format ("060102150405 " ) // yyMMddhhmmss
31- fileName := fmt .Sprintf ("user_ %s_%s%s" , userID , timestamp , ext )
45+ timestamp := time .Now ().Format ("060102_150405 " ) // yyMMdd_hhmmss
46+ fileName := fmt .Sprintf ("%s_%s%s" , username , timestamp , ext )
3247
3348 srcFile , err := file .Open ()
3449 if err != nil {
0 commit comments