Skip to main content

Upload a file

  • Step 1 : Retrieve the upload URL.
  • Step 2 : Upload the file using the URL via the PUT method.
  • Step 3 : Mark the file upload as successful.

To retrieve an upload URL

This API generates a pre-signed URL for file uploads, allowing files to be uploaded directly to the specified location. Please note that the URL is time-sensitive and will expire after 5 minutes.

Endpoint

POST https://usapi.hottask.com/chat/User/GetPreUploadUrl

Request Headers

The API request must include the following headers:

  • Authorization: <Your-Secret-Key> - The secret key for authenticating the API request.
  • Content-Type: application/json - The content type of the request payload.

Request Body

The request body should contain the following parameters:

{
// fileName(string, required): The filename. EG: companyinfo.txt
"fileName":"companyinfo.txt"
}

Example Request

JavaScript (Fetch API)
const res = await fetch('https://usapi.hottask.com/chat/User/GetPreUploadUrl', {
method: 'POST',
headers: {
'Authorization': `<Your-Secret-Key>`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
fileName: '<Your filename>',
}),
});

const data = await res.json();
console.log(data);
Python (Requests Library)
import requests
import json

url = 'https://usapi.hottask.com/chat/User/GetPreUploadUrl'
headers = {
'Authorization': '<Your-Secret-Key>',
'Content-Type': 'application/json'
}
data = {
'fileName': '<Your filename>'
}

response = requests.post(url, headers=headers, data=json.dumps(data))
data = response.json()

print(data)
cURL
curl https://usapi.hottask.com/chat/User/GetPreUploadUrl \
-H 'Content-Type: application/json' \
-H 'Authorization: <Your-Secret-Key>' \
-d '{"fileName": "your filename"}'
HTTP Request
POST /chat/User/GetPreUploadUrl HTTP/1.1
Host: usapi.hottask.com
Authorization: <Your-Secret-Key>
Content-Type: application/json

{
"fileName": "<Your filename>"
}

Response

The API response will be a JSON object with the following structure:

{
"Data": {
"FileStoreId":"34317",
"PreUploadUrl":"https://xxx.s3.us-west-1.amazonaws.com/xxx/3706/627855d5-ba01-4732-9dfd-b08a72744c77.txt?X-Amz-Expires=600\u0026X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIA5TS7CBKE4ZSWBI46%2F20250121%2Fus-west-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20250121T030214Z\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=a237335d9b2e6fad1c648f753d393906647db5528eaaecf5e55dd114a22653db",
},
"Version": "1.0.0",
"Success": true,
"Code": 200,
"Message":""
}

Error Handling

If it's an HTTP network error, you should check the HTTP status code. If it's a business exception, you need to examine the Code and Message fields, which will provide the error details.

That’s it! You should now be able to create a chatbot using the create API.

Mark the upload as successful

This API allows the user to mark the file as successfully uploaded.

Endpoint

POST https://usapi.hottask.com/chat/User/ReportUploadSuccess

Request Headers

The API request must include the following headers:

  • Authorization: <Your-Secret-Key> - The secret key for authenticating the API request.
  • Content-Type: application/json - The content type of the request payload.

Request Body

The request body should contain the following parameters:

{
// fileStoreID(string, required): The file id.
"fileStoreID":"123"
}

Example Request

JavaScript (Fetch API)
const res = await fetch('https://usapi.hottask.com/chat/User/ReportUploadSuccess', {
method: 'POST',
headers: {
'Authorization': `<Your-Secret-Key>`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
fileStoreID: '123'
}),
});

const data = await res.json();
console.log(data);
Python (Requests Library)
import requests
import json

url = 'https://usapi.hottask.com/chat/User/ReportUploadSuccess'
headers = {
'Authorization': '<Your-Secret-Key>',
'Content-Type': 'application/json'
}
data = {
'fileStoreID': '123'
}

response = requests.post(url, headers=headers, data=json.dumps(data))
data = response.json()

print(data)
cURL
curl https://usapi.hottask.com/chat/User/ReportUploadSuccess \
-H 'Content-Type: application/json' \
-H 'Authorization: <Your-Secret-Key>' \
-d '{"fileStoreID": "123"}'
HTTP Request
POST /chat/User/ReportUploadSuccess HTTP/1.1
Host: usapi.hottask.com
Authorization: <Your-Secret-Key>
Content-Type: application/json

{
"fileStoreID": "123"
}

Response

The API response will be a JSON object with the following structure:

{
"Data": true,
"Version": "1.0.0",
"Success": true,
"Code": 200,
"Message":""
}

Error Handling

If it's an HTTP network error, you should check the HTTP status code. If it's a business exception, you need to examine the Code and Message fields, which will provide the error details.

That’s it! You should now be able to upload a file using these two APIs.