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:
PutSingle - uploading an entire object in a single request;
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.
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:
Execution context
Method arguments, which includes:
Container ID
Payload
Additional headers (optional)
Result:
Object ID
1 2 3 4 5 6 7 8 91011
publicstaticObjectIdexamplePutSingle(FrostFSClientfrostFSClient,ContainerIdcontainerId,CallContextcallContext,byte[]bytes){// Creating an ObjectObjectFrostFSobjectFrostFS=newObjectFrostFS(containerId,bytes,ObjectType.REGULAR);// Adding attributesvarattribute=newObjectAttribute("Filename","file");objectFrostFS.getHeader().getAttributes().add(attribute);varprmObjectPut=PrmObjectSinglePut.builder().objectFrostFS(objectFrostFS).build();returnfrostFSClient.putSingleObject(prmObjectPut,callContext);}
1 2 3 4 5 6 7 8 9101112131415161718
publicstaticasyncTask<FrostFsObjectId>ExamplePutSingle(IFrostFSClientclient,FrostFsContainerIdcontainerId,byte[]bytes){// Creating a Headervarheader=newFrostFsObjectHeader(containerId:containerId,type:FrostFsObjectType.Regular,[new FrostFsAttributePair("fileName", "test")]);// Creating an Objectvarobj=newFrostFsObject(header){SingleObjectPayload=bytes};varparam=newPrmSingleObjectPut(obj);returnawaitclient.PutSingleObjectAsync(param,default).ConfigureAwait(true);}
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.
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 910
publicstaticvoidputObjectServerCut(FrostFSClientfrostFSClient,ContainerIdcontainerId,CallContextcallContext,byte[]bytes){// Creating a Headervarattribute=newObjectAttribute("Filename","file");varcat=newObjectHeader(containerId,ObjectType.REGULAR,attribute);varprmObjectPut=PrmObjectPut.builder().objectHeader(cat).build();varwriter=frostFSClient.putObject(prmObjectPut,callContext);writer.write(file.readAllBytes());returnwriter.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.