Skip to content

Uploading Objects

The SDK provides several methods for uploading objects.

Note

Uploading using client cut chunking is described in a separate section

This section covers two main upload methods:

  1. PutSingle - uploading an entire object in a single request;
  2. Put - streaming upload.

Limitations

Both methods share a common limitation defined by the maxObjectSize parameter in the network settings. This value sets the maximum object size for the PutSingle method and the maximum size of each chunk for the Put method.

Attempting to upload an object or a chunk exceeding this size will result in an error.

PutSingle

A method for uploading an object in a single request. Recommended for small-sized objects. You need to provide the container identifier where the upload will occur, as well as the byte array of the object being uploaded.

Arguments:

  1. Execution context
  2. Method arguments, which includes:
    • Container ID
    • Payload
    • Additional headers (optional)

Result:

  • Object ID
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
public static ObjectId examplePutSingle(FrostFSClient frostFSClient, ContainerId containerId, CallContext callContext, byte[] bytes) {
    // Creating an Object
    ObjectFrostFS objectFrostFS = new ObjectFrostFS(containerId, bytes, ObjectType.REGULAR);

    // Adding attributes
    var attribute = new ObjectAttribute("Filename", "file");
    objectFrostFS.getHeader().getAttributes().add(attribute);

    var prmObjectPut = PrmObjectSinglePut.builder().objectFrostFS(objectFrostFS).build();
    return frostFSClient.putSingleObject(prmObjectPut, callContext);
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
 public static async Task<FrostFsObjectId> ExamplePutSingle(
    IFrostFSClient client,
    FrostFsContainerId containerId,
    byte[] bytes)
{
    // Creating a Header
    var header = new FrostFsObjectHeader(
        containerId: containerId,
        type: FrostFsObjectType.Regular,
        [new FrostFsAttributePair("fileName", "test")]);

    // Creating an Object
    var obj = new FrostFsObject(header) { SingleObjectPayload = bytes };

    var param = new PrmSingleObjectPut(obj);

    return await client.PutSingleObjectAsync(param, default).ConfigureAwait(true);
}

Not available

Put

A method for uploading objects of any size using a streaming interface. Uploading is performed in chunks, with processing and chunking handled by the storage side.

Arguments:

  1. Execution context
  2. Method arguments, which includes:
    • Container ID
    • Additional headers (optional)

Result:

  • writer
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
func PutObjectServerCut(ctx context.Context, p pool.Pool, cnrID cid.ID) error {
    attributes := make([]object.Attribute, 0)
    filename := object.NewAttribute()
    filename.SetKey(object.AttributeFileName)
    filename.SetValue("name.txt")

    attributes = append(attributes, *filename)

    obj := object.New()
    obj.SetOwnerID(owner)
    obj.SetContainerID(cnrID)
    obj.SetAttributes(attributes...)

    var prmPut pool.PrmObjectPut
    prmPut.SetHeader(*obj)
    prmPut.SetPayload(bytes.NewReader([]byte("testing")))
    objID, err := p.PutObject(ctx, prmPut)
}

Only a header containing the object's meta-information is sent in the initial request. As a result of the method call, a writer is returned. This writer is used to pass byte arrays until the entire object is transferred. Upon completion, it is necessary to call writer.complete() to finalize the upload and receive the object identifier.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
public static void putObjectServerCut(FrostFSClient frostFSClient, ContainerId containerId, CallContext callContext, byte[] bytes) {
    // Creating a Header
    var attribute = new ObjectAttribute("Filename", "file");
    var cat = new ObjectHeader(containerId, ObjectType.REGULAR, attribute);
    var prmObjectPut = PrmObjectPut.builder().objectHeader(cat).build();
    var writer = frostFSClient.putObject(prmObjectPut, callContext);

    writer.write(file.readAllBytes());
    return writer.complete();
}

Only a header containing the object's meta-information is sent in the initial request. As a result of the method call, a writer is returned. This writer is used to pass byte arrays until the entire object is transferred. Upon completion, it is necessary to call writer.CompleteAsync() to finalize the upload and receive the object identifier.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
 public static async Task<FrostFsObjectId> PutObjectServerCut(IFrostFSClient client, FrostFsContainerId containerId, byte[] bytes)
{
    var header = new FrostFsObjectHeader(
        containerId: containerId,
        type: FrostFsObjectType.Regular,
        [new FrostFsAttributePair("fileName", "test")]);

    var param = new PrmObjectPut(header);
    var writer = await client.PutObjectAsync(param, default);

    if (bytes.Length > 0)
    {
        await writer.WriteAsync(bytes);
    }

    return await writer.CompleteAsync();
}