UploadAgentSessionFile
Issues a file upload URL for an agent session and confirms writing the file to the session instance for reference in subsequent conversations. This API operation is available only when the canary release feature is enabled. Before calling this operation, verify that the canary release feature is enabled for your account and the target region.
Operation description
This API operation is available only when the canary release feature is enabled. Before calling this operation, verify that the canary release feature is enabled for your account and the target region.
Uploads a local file to an agent session that the caller has access to, and references the file in the conversation. The size of a single file ranges from 1 byte to 10,485,760 bytes (10 MiB). The caller must have access permissions to the target session and the dataworks:UploadAgentSessionFile permission.
Call sequence.
Use the SessionId of an existing session, set UploadMode to prepare, and pass the original file name, the byte size Size, and the 32-character lowercase hexadecimal ContentMd5 of the original bytes. The prepare mode returns UploadId and Signature. It only issues an upload URL and does not start a cold session instance.
Within the validity period of the signature, send an HTTP PUT request to Signature.Url. Set the request body to the original bytes of the file and use all the request headers returned in Signature.Headers. The URL and request headers must be used exactly as returned. The ContentMd5 parameter is in hexadecimal format, whereas the Content-MD5 signature header is Base64-encoded. The two formats are not interchangeable. The signature is valid for 5 minutes. For the exact expiration time, see ExpiresAt.
After the PUT request succeeds, set UploadMode to complete, pass the UploadId returned by prepare, and keep SessionId, Name, Size, and ContentMd5 consistent. The server resumes the session. The runtime in the instance downloads the staged object, verifies the size and MD5 hash, writes the file to the working directory, and returns Id, Name, RelativePath, and Size. Repeated complete calls use the same UploadId. The same attachment receipt is returned only when the existing file content is identical.
Call PromptAgentSession. Add a content block with Type set to resource_link, Name set to the original file name, and Uri set to dataagent-attachment: followed by RelativePath in Params.Prompt, and send it together with the text content block. The backend resolves the reference to the working directory of the session based on the current authenticated session.
For the sample file sample.csv, the original bytes are hello followed by a line feed. Size is 6, and ContentMd5 is b1946ac92492d2347c6235b4d2611184. The SessionId example session and the upload identifier examples are used only to illustrate the parameter structure. For actual calls, you must use a created session and the values returned by prepare. The Signature.Url example is used only to illustrate the format. For the actual PUT request, you must use the complete signed URL returned by the current prepare call.
Error handling.
You must check the outer POP/BFF failures, JsonRpcResponse.Error, and the expected result fields at the same time. Missing upload stages or oversized files may result in an HTTP 400 error returned by the gateway, such as MissingUploadMode or InvalidSize. Business rejections such as non-existent objects or metadata mismatches return an HTTP 400 error and a general Code 400 in the public POP. The Message field retains the actual business code, such as SESSION_ATTACHMENT_OBJECT_MISMATCH. Dependency failures, HTTP 5xx errors, timeouts, and unknown execution results must not be treated as parameter rejections or successful uploads. Do not automatically retry the write operation. When the result is unknown, retain the original upload metadata and UploadId, and verify the result first.
This API operation does not accept ContentBase64. Signature expiration only invalidates the upload authorization and does not indicate that the staged object is deleted. This documentation does not guarantee an automatic cleanup cycle for objects.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
dataworks:UploadAgentSessionFile |
create |
*All Resource
|
None | None |
Request syntax
POST HTTP/1.1
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| Jsonrpc |
string |
No |
The JSON-RPC protocol version. The example uses 2.0. |
2.0 |
| Id |
string |
No |
The JSON-RPC correlation ID for the current request. The Id in the response returns this value exactly as passed to correlate the request and response. |
attachment-rpc-001 |
| Params |
object |
Yes |
The parameter object for the upload stage. The prepare stage issues an upload URL, and the complete stage confirms that the file is written to the target session instance. |
|
| SessionId |
string |
Yes |
The ID of the target agent session. |
session |
| Name |
string |
Yes |
The original file name. The maximum length is 255 bytes in UTF-8 encoding. |
sample.csv |
| UploadMode |
string |
Yes |
The required upload stage. The prepare stage issues a public OSS PUT URL and does not start a cold session instance. The complete stage resumes the session and allows the runtime to download the file. Valid values:
|
prepare |
| Size |
integer |
Yes |
The number of original bytes. Valid values: 1 to 10485760 (10 MiB). This parameter is required for both the prepare and complete stages and must remain consistent. |
6 |
| ContentMd5 |
string |
Yes |
The MD5 hash of the original bytes, represented as a 32-character lowercase hexadecimal string. This parameter is required for both the prepare and complete stages and must remain consistent. |
b1946ac92492d2347c6235b4d2611184 |
| UploadId |
string |
No |
The upload ID returned by the prepare stage. This parameter is required when UploadMode is set to complete. |
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The request correlation information and the JSON-RPC success result or error object. For public calls, you must also check the outer POP/BFF errors. |
||
| RequestId |
string |
The server correlation ID for the current request. You can provide this value for troubleshooting. |
01A0B6E0-E005-1465-B5DE-5CD17677426F |
| JsonRpcResponse |
object |
The JSON-RPC response. Returns Result upon success and Error upon a protocol error. |
|
| Jsonrpc |
string |
The JSON-RPC protocol version. |
2.0 |
| Id |
string |
The JSON-RPC correlation ID for the current request. It is passed by the caller and returned exactly as passed. |
attachment-rpc-001 |
| Timestamp |
integer |
The response time, represented as a UNIX timestamp in milliseconds. |
1789549200000 |
| Result |
object |
Issues a staged upload URL or returns the attachment information after the file is written to the instance. |
|
| UploadId |
string |
The staged upload ID issued by the prepare stage. |
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
| Signature |
object |
The time-limited Object Storage Service (OSS) signature returned by the prepare stage. |
|
| Url |
string |
The complete signed HTTPS PUT URL returned by the prepare stage. It must be used exactly as returned for the upload. The example displayed for this field does not contain a valid signature. For actual requests, use the value returned in the current call. |
https://attachments.example.test/signed |
| Headers |
object |
All signed request headers that must be included in the PUT request. The names and values must be used exactly as returned. This includes Content-Type, Content-MD5, Content-Length, x-oss-object-acl, and x-oss-forbid-overwrite. |
{"Content-Type":"application/octet-stream","Content-MD5":"sZRqySSS0jR8YjW00mERhA==","Content-Length":"6","x-oss-object-acl":"private","x-oss-forbid-overwrite":"true"} |
|
string |
The string value of the signed request header. The example corresponds to Content-Type. For other keys, you must use the original strings returned by the current prepare call. |
application/octet-stream |
|
| ExpiresAt |
string |
The expiration time of the current upload signature, represented as an ISO 8601 UTC string. The trailing Z indicates UTC, and fractional seconds may be included. The signature is valid for 5 minutes. Signature expiration does not indicate that the staged object is deleted. |
2026-11-12T09:46:33.477365753Z |
| Id |
string |
The ID of the attachment. |
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
| Name |
string |
The original file name. |
sample.csv |
| RelativePath |
string |
The relative path in the working directory of the session. |
upload/session_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.csv |
| Size |
integer |
The number of bytes of the file saved in the instance. |
6 |
| Error |
object |
The JSON-RPC fault message. This field is not returned upon success. |
|
| Code |
integer |
The JSON-RPC error code. |
400 |
| ErrorCode |
string |
The business error code. |
SESSION_ATTACHMENT_OBJECT_MISMATCH |
| Message |
string |
The error message. |
SESSION_ATTACHMENT_OBJECT_MISMATCH |
| Data |
any |
The optional additional error information. The content depends on the error type. |
{} |
Examples
Success response
JSON format
{
"RequestId": "01A0B6E0-E005-1465-B5DE-5CD17677426F",
"JsonRpcResponse": {
"Jsonrpc": "2.0",
"Id": "attachment-rpc-001",
"Timestamp": 1789549200000,
"Result": {
"UploadId": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"Signature": {
"Url": "https://attachments.example.test/signed",
"Headers": {
"key": "application/octet-stream"
},
"ExpiresAt": "2026-11-12T09:46:33.477365753Z"
},
"Id": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"Name": "sample.csv",
"RelativePath": "upload/session_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.csv",
"Size": 6
},
"Error": {
"Code": 400,
"ErrorCode": "SESSION_ATTACHMENT_OBJECT_MISMATCH",
"Message": "SESSION_ATTACHMENT_OBJECT_MISMATCH",
"Data": "{}"
}
}
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.