in this page it is described how to automatically support REST requests in an existing GRPC server
https://cloud.google.com/endpoints/docs/grpc/transcoding
But there is no mention for file upload support . For example is it possible to support requests such as this
curl -F "image=@/home/user1/Desktop/test.jpg" localhost/uploader.php
with this or similar methods ?
The grpc code handles files in this way :
Proto files:
service serviceName {
...
rpc WriteApi(TarFile) returns (Status) { }
...
}
message TarFile {
bytes contents = 1;
string somethingElse =2;
}
and in the serving function something like :
func (server *Server) WriteApi(ctx context.Context, jf1 *pb.TarFile) (*pb.Status, error) {
buf1 := bytes.NewBuffer(jf1.Contents)
tr1 := tar.NewReader(buf1)
for {
hdr1, err1 := tr1.Next()
if err1 == io.EOF {
break
}
if err1 != nil {
log.Fatal(err1)
}
bud1 := new(bytes.Buffer)
bud1.ReadFrom(tr1)
s1 := bud1.String()
l4g.Info(s1)
ioutil.WriteFile(rseedstr+"/"+hdr1.Name, []byte(s1), 0644)
}