From 73806a8a5401351caecf880c3ebca7fd942b9960 Mon Sep 17 00:00:00 2001 From: Sigrid Date: Tue, 22 Nov 2022 21:28:38 +0900 Subject: [PATCH] fix: wrong file write bytes to correct this! - https://mingrammer.com/gobyexample/writing-files/ --- README.md | 2 +- preprocess/registry.go | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cf8483b..0ea49da 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Recording S3 upload dedicated Microservice to deliverble restful server * only [deliverble restful server](https://github.com/DeliverBle/deliverble-backend-nestjs) is allowed to communicate with the MSA module ### does not * provide any other functionality other than uploading mp3 file in s3 bucket -* delete feature or change naming strategy should be done in the restful server (nothing to do with bucket itself) +* delete feature, change naming feature or listing all recordings by User Identity should be done in the restful server (nothing to do with bucket itself) ## How to start ``` diff --git a/preprocess/registry.go b/preprocess/registry.go index c95de44..f790ce7 100644 --- a/preprocess/registry.go +++ b/preprocess/registry.go @@ -21,6 +21,7 @@ import ( "github.com/labstack/echo" _ "github.com/labstack/echo/v4" "google.golang.org/grpc" + "io/ioutil" "log" "net/http" "os" @@ -150,14 +151,11 @@ func (s *S3Server) UploadRecording(_ context.Context, req *recordingpb.UploadRec filename := fmt.Sprintf("%v.mp3", time.Now().Unix()) filepath := "/tmp/" + filename + ".mp3" - rec, err := os.Create(filepath) + err = ioutil.WriteFile(filepath, req.Recording, 0644) if err != nil { - log.Println("Error creating file: ", err) + log.Println("Error writing to file: ", err) return nil, err } - defer rec.Close() - - fmt.Fprintf(rec, string(req.Recording)) var response *recordingpb.UploadRecordingResponse recording, err := info.UploadRecording(filename, filepath)