Uploading Data to a DIS Stream
Function
This API is used to upload data to a DIS stream.
- Before uploading data, you need to create a stream by referring to Creating a DIS Stream.
- When uploading data, you need to specify the partition ID of the stream. The partition ID can be obtained from Viewing Details of a DIS Stream.
Request
- Example request
POST https://{endpoint}/v2/{project_id}/records { "stream_name": "stream_test", "records": [ { "data": "MTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTE=", "explicit_hash_key": null, "partition_key": "0" ] } - Parameter description
Table 1 Parameter description Parameter
Mandatory
Type
Description
stream_name
Yes
String
Name of the stream created on the management console.
A stream name is 1 to 64 characters long. Only letters, digits, hyphens (-), and underscores (_) are allowed.
stream_id
No
String
Unique ID of the stream.
If no stream is found based on stream_name and stream_id is not empty, stream_id is used to search for the stream.
NOTE:This parameter is mandatory when you upload data to a stream that has been authorized.
records
Yes
List<PutRecordsRequestEntry>
Information of data records.
For more information, see Table 2.
Table 2 records parameter description Parameter
Mandatory
Type
Description
data
Yes
Base64-encoded binary data object
Data to be put into the chosen DIS stream.
The uploaded data must be serialized into binary Base64-encoded data.
explicit_hash_key
No
String
Hash value used to explicitly determine the partition into which an individual data record will be put. The hash value overrides the partition key hash.
Value range: 0 to long.max
partition_id
No
String
Unique identifier of the partition.
partition_key
No
String
Partition key of the partition into which an individual data record will be put.
NOTE:The partition_id parameter takes precedence over the partition_key parameter. If the partition_id parameter is not passed in, then the partition_key parameter is selected for use.
- The user's raw data may contain invisible characters. Therefore, the raw data must be encoded using Base64 encoding before invoking the API.
- If a user uploads data using SDK provided by DIS, the SDK will automatically encode the raw data using Base64 encoding.
Response
- Example response
{ "failed_record_count": 0, "records": [ { "sequence_number": "195", "partition_id": "shardId-0000000000" } ] } - Parameter description
Table 3 Response parameter description Parameter
Type
Description
failed_record_count
Int
The number of data records that failed to be put into the selected DIS stream.
records
List<PutRecordResult>
Processing result of each data record.
For more information, see Table 4.
Table 4 PutRecordResult parameter description Parameter
Type
Description
error_code
String
Error code for an individual record result.
error_message
String
Error message for an individual record result.
partition_id
String
Partition ID for an individual record result.
sequence_number
String
Sequence number of an individual data record. Each data record has a sequence number that is unique within its partition. The sequence number is assigned by DIS when a data producer calls PutRecords to add data to a DIS stream. Sequence numbers for the same partition key generally increase over time; the longer the time period between write requests (PutRecords requests), the larger the sequence numbers become.
Status Code
- Normal
- Failed
For more information, see Error Codes.
Last Article: Viewing Details of a DIS Stream
Next Article: Obtaining a Cursor
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.