fileUpload_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package test
  2. import (
  3. "app.yhyue.com/moapp/jyfs/rpc/filesystem"
  4. "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
  5. "fmt"
  6. "github.com/gogf/gf/v2/os/gctx"
  7. "github.com/zeromicro/go-zero/core/discov"
  8. "github.com/zeromicro/go-zero/zrpc"
  9. "google.golang.org/grpc"
  10. "log"
  11. "testing"
  12. )
  13. var (
  14. Domain = "jydocs-std"
  15. )
  16. func Test_FileUpload(t *testing.T) {
  17. log.Println("-------------")
  18. //获取附件后上传oss
  19. fr := &filesystem.SaveFileReq{
  20. Domain: Domain,
  21. FileId: fmt.Sprintf("%s.%s", "101010", "doc"),
  22. Meta: map[string]string{
  23. "docName": "101020",
  24. "docSuffix": "doc",
  25. "docSize": "24",
  26. },
  27. RawFileContent: []byte("我是中国人"),
  28. }
  29. if fr != nil && len(fr.RawFileContent) > 0 {
  30. conf := zrpc.RpcClientConf{
  31. Etcd: discov.EtcdConf{
  32. Key: "moapp.filesystem.rpc",
  33. Hosts: []string{"192.168.3.206:2379"},
  34. },
  35. }
  36. grpcOpts := []zrpc.ClientOption{
  37. //zrpc.WithDialOption(grpc.WithWriteBufferSize(40 * 1024 * 1024)), // 设置发送消息的最大字节数,这里是40MB
  38. //zrpc.WithDialOption(grpc.WithReadBufferSize(40 * 1024 * 1024)), // 设置接收消息的最大字节数,这里也是40MB
  39. zrpc.WithDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(40 * 1024 * 1024))),
  40. zrpc.WithDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(40 * 1024 * 1024))),
  41. }
  42. client := zrpc.MustNewClient(conf, grpcOpts...)
  43. jyFilelLib := filesystemclient.NewFileSystem(client)
  44. fRes, err := jyFilelLib.SaveFile(gctx.New(), fr)
  45. log.Println(fRes, "----------", err)
  46. }
  47. }
  48. func Test_GetFile(t *testing.T) {
  49. jyFilelLib := filesystemclient.NewFileSystem(zrpc.MustNewClient(zrpc.RpcClientConf{
  50. Etcd: discov.EtcdConf{
  51. Key: "moapp.filesystem.rpc",
  52. Hosts: []string{"192.168.3.206:2379"},
  53. },
  54. }))
  55. resp, err := jyFilelLib.GetOssUril(gctx.New(), &filesystem.LoadFileReq{
  56. Domain: Domain,
  57. FileId: "335a98b93b81dd3a0488a1eecac55d4a.pdf",
  58. })
  59. log.Println(resp, "-----", err)
  60. }