We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When I tried it, I expected the bytes to be saved on the server side.
I tweaked the sources to make that happen:
diff --git a/core/grpc_client.go b/core/grpc_client.go index b5255ca..6a54e1c 100644 --- a/core/grpc_client.go +++ b/core/grpc_client.go @@ -4,6 +4,7 @@ import ( "io" "os" "time" + "fmt" "github.com/cirocosta/gupload/messaging" "github.com/pkg/errors" @@ -159,6 +160,7 @@ func (c *ClientGRPC) UploadFile(ctx context.Context, f string) (stats Stats, err status.Message) return } + fmt.Printf("upload succeeded: <<%s>>\n", status.Message) return } diff --git a/core/grpc_server.go b/core/grpc_server.go index 5d5e4fa..7798ae9 100644 --- a/core/grpc_server.go +++ b/core/grpc_server.go @@ -5,6 +5,8 @@ import ( "net" "os" "strconv" + "time" + "fmt" "github.com/cirocosta/gupload/messaging" "github.com/pkg/errors" @@ -88,33 +90,59 @@ func (s *ServerGRPC) Listen() (err error) { } func (s *ServerGRPC) Upload(stream messaging.GuploadService_UploadServer) (err error) { + fmt.Println("server upload()...") + var timeInUTC time.Time + var strTimeInUTC string + var location *time.Location + var err1 error + var err3 error + var err4 error + var theChunk *messaging.Chunk + + location, err3 = time.LoadLocation("Canada/Eastern") + if err3 != nil { + fmt.Println("loadlocation failed") + } + + timeInUTC = time.Now() + strTimeInUTC = timeInUTC.In(location).Format("2006-01-02T15:04:05.999999999Z07:00") + fmt.Printf("<<%s>>\n", strTimeInUTC) + fo, err := os.Create(strTimeInUTC) + if err != nil { + return err + } + defer fo.Close() + for { - _, err = stream.Recv() - if err != nil { - if err == io.EOF { + theChunk, err1 = stream.Recv() + if err1 != nil { + if err1 == io.EOF { goto END - } + } - err = errors.Wrapf(err, - "failed unexpectadely while reading chunks from stream") return } + + _, errWrite := fo.Write(theChunk.Content) + if errWrite != nil { + return errWrite + } } - s.logger.Info().Msg("upload received") - + END: - err = stream.SendAndClose(&messaging.UploadStatus{ - Message: "Upload received with success", + + fmt.Println("upload received") + + err4 = stream.SendAndClose(&messaging.UploadStatus{ + Message: string(strTimeInUTC), Code: messaging.UploadStatusCode_Ok, }) - if err != nil { - err = errors.Wrapf(err, - "failed to send status code") + if err4 != nil { return } - return + return } func (s *ServerGRPC) Close() {
The text was updated successfully, but these errors were encountered:
No branches or pull requests
When I tried it, I expected the bytes to be saved on the server side.
I tweaked the sources to make that happen:
The text was updated successfully, but these errors were encountered: