From 2470e2cfb1511823faa667166f4f5f4305f2031c Mon Sep 17 00:00:00 2001 From: P4vlushaaa <112944483+P4vlushaaa@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:05:04 +0300 Subject: [PATCH] Create uploader.go --- .../internal/frostuploader/uploader.go | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 services/frostfs-uploader/internal/frostuploader/uploader.go diff --git a/services/frostfs-uploader/internal/frostuploader/uploader.go b/services/frostfs-uploader/internal/frostuploader/uploader.go new file mode 100644 index 0000000..f2085a4 --- /dev/null +++ b/services/frostfs-uploader/internal/frostuploader/uploader.go @@ -0,0 +1,28 @@ +package frostuploader + +import ( + "context" + "io" + + "github.com/nspcc-dev/neofs-sdk-go/client" + "github.com/nspcc-dev/neofs-sdk-go/client/object" + "github.com/nspcc-dev/neofs-sdk-go/container" +) + +func UploadFile(ctx context.Context, cli *client.Client, cntr container.ID, data []byte) (string, error) { + obj := object.New() + obj.SetPayload(data) + + writer, err := cli.ObjectPutInit(ctx, cntr, obj) + if err != nil { + return "", err + } + if _, err := writer.Write(data); err != nil { + return "", err + } + oid, err := writer.Close() + if err != nil { + return "", err + } + return oid.String(), nil +}