Skip to content

gupload doesn't actually save the bytes received on the server side #7

@omac777

Description

@omac777

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() {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions