Skip to content

Getting objects

To retrieve an object, you need to know its ID as well as the ID of the container where it is stored. The result will be presented as sequential chunks received in response to the request until the entire object has been read.

Arguments:

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

Result:

  • Object reader
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
func GetObject(ctx context.Context, p pool.Pool, addr oid.Address) string {
    var prm pool.PrmObjectGet
    prm.SetAddress(addr)

    res, err := p.GetObject(ctx, prm)
    die(err)
    payload, err := io.ReadAll(res.Payload)
    die(err)
    return string(payload)
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public static void getObject(FrostFSClient frostFSClient, ContainerId containerId, ObjectId objectId,
                                 CallContext callContext) {
    var prmObjectGet = new PrmObjectGet(containerId, objectId);
    ObjectFrostFS object = frostFSClient.getObject(prmObjectGet, callContext);

    var reader = object.getObjectReader();
    var chunk = reader.readChunk();
    var length = chunk.length;
    byte[] buffer = null;
    while (length > 0) {
        buffer = isNull(buffer) ? chunk : ArrayHelper.concat(buffer, chunk);

        chunk = object.getObjectReader().readChunk();
        length = ArrayUtils.isEmpty(chunk) ? 0 : chunk.length;
    }
}
1
2
3
4
5
6
7
8
9
public static async Task<FrostFsObject> GetObjectAsync(
    FrostFSClient client, 
    FrostFsContainerId containerId, 
    FrostFsObjectId objectId)
{
    var args = new PrmObjectGet(containerId, objectId);

    return await client.GetObjectAsync(args, default);
}