Create uploader.go
This commit is contained in:
parent
749152fc03
commit
2470e2cfb1
1 changed files with 28 additions and 0 deletions
28
services/frostfs-uploader/internal/frostuploader/uploader.go
Normal file
28
services/frostfs-uploader/internal/frostuploader/uploader.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Reference in a new issue