tencent cloud

Smart Media Hosting

Product Introduction
Product Overview
Feature Description
Product Strengths
Use Cases
Basic Concept
Purchase Guide
Quick Start
Create Media Library
Initiate request
Service Level API Document
History
Introduction
API Category
Making API Requests
PaaS Service APIs
Official Cloud Disk APIs
Data Types
Error Codes
Business Level API Document
Introduction
Access Token Operation API
Tenant Space Operation API
File Operation API
Directory or Album Operation API
Recycle Bin Operation API
Quota Operation API
Query Task Operation API
Search Operation API
Historical Version Operations API
Directory and File Batch Operation API
Collection Operation API
Error Codes
SDK Documentation
Android SDK
iOS SDK
HarmonyOS SDK
FAQs
Enterprise Network Disk
Product Introduction
Purchase Guide
Quick Start
FAQs
Service Level Agreement
Glossary

Form Upload File

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-01-07 14:15:04

Description

Start form file upload.
Note:
Required permissions: admin, space_admin, or upload_file/upload_file_force/begin_upload/begin_upload_force. For details on permissions, see Generate Access Token Interface.
Calling this API returns a set of parameters for form-based file upload (multipart/form-data format) and confirming upload completion. The target URL for upload is https://{Domain}/, where {Domain} is the domain field in the response body, for example, https://examplebucket-1250000000.cos.ap-beijing.myqcloud.com/.
During form-based file upload, a series of additional information fields need to be specified. The names and values of these fields are contained in the form field of the response body. They can be specified in HTML forms through hidden fields, or via JavaScript libraries, mini-program wx.uploadFile, and so on.
The file field in the form, whose field name is fixed as "file", must be the last field in the form.
After the actual upload is completed, the target upload URL will return HTTP 204 No Content. Due to possible cross-origin restrictions, it is recommended to determine whether the upload is complete directly through the callback of the relevant interface, and promptly call the Complete File Upload interface to confirm the upload result after completion.
By default, files with the same name will be automatically renamed. The final file path can be obtained from the interface for file upload completion.
It does not automatically create the required parent directories, so you must ensure that all levels of directories in the path exist.
Media libraries for media types do not support uploading files with file extensions.

Request

Request Example

POST /api/v1/file/{LibraryId}/{SpaceId}/{FilePath}?conflict_resolution_strategy={ConflictResolutionStrategy}&filesize={FileSize}&access_token={AccessToken}&user_id={UserId}

Request Parameter

Request parameters.
Description
Type
Required or Not
LibraryId
Media Library ID, obtained after creating a media library in the media hosting console, please refer to create media library
String
Yes
SpaceId
Space ID. If the media library is in single-tenant mode, this parameter is fixed as hyphen (`-`); if the media library is in multi-tenant mode, you must specify this parameter. Please refer to create tenant space for retrieval.
String
No
FilePath
Complete file path, for example foo/bar/file.docx. Please refer to view directory or album for retrieval.
String
Yes
FileSize
Upload file size in bytes (Byte), used to judge if available space is sufficient.
String
No
ConflictResolutionStrategy
Handling method for filename conflict, default is rename:
ask: Returns HTTP 409 Conflict and SameNameDirectoryOrFileExists error code when conflicts with
rename: Automatically rename file when conflicts with
overwrite:
If the target is a directory or album, it defaults to ask and does not support overwrite.
If the target is a file, overwrite the existing file.
When an earlier version of the file exists in the target space, moving to overwrite is not supported.
String
No
AccessToken
Access token. To obtain it, see Generate Access Token
String
Yes
UserId
User identity recognition. When the permission corresponding to the access token is admin permission and the user identity recognition when applying for the access token is empty, it is used to temporarily specify user identity. For details, see Generate Access Token API
String
No
TrafficLimit
Single link download speed limit, range 100KB/s-100MB/s, Unit B
Number
No
PreferSameOrigin
Whether to keep the same domain name, valid values: true or false
This parameter is valid only when there is a file with the same name in the upload file path and ConflictResolutionStrategy is set to rename or overwrite.
When this parameter is set, the backend will try to ensure the newly uploaded file uses the same domain name as the original file for upload or download. However, in special cases, different domain names may still be used, so you should not rely too much on this parameter.
Boolean
No

Request Header

x-smh-meta-*: custom metadata.

Request Body

{
"fullHash": "9fee55123adad49e5090236eead6a8a9edc9caaa0f97b9e38c3713c1b97b9d29",
"beginningHash": "9faskdfhwek2h3r4kjdsjkahfsdkfhjaksdldc9caaa0f97b9e38c3713c1b97b9d29",
"size": "2081112",
"labels":["elephant","animal","Asian elephant"],
"category":"video",
"localCreationTime": "2022-07-26T02:58:09Z",
"localModificationTime": "2022-07-26T02:58:09Z"
}
Request body fields:
Request parameters.
Description
Type
Required or Not
beginningHash
The fullHash value of the first 1MB of the file, used for instant upload: the sha256 hash value of the first 1MB of the file.
String
No
fullHash
The fullHash value of the file defined by SMH, used for instant upload. The following algorithm:
Fetch the first 1MB of the file, calculate the sha256, and use the result as both beginningHash and fullHash.
Continue fetching the next 1MB segment of the file, calculate fullHash and the sha256 of the current 1MB data, sha256(Buffer.concat([Buffer.from(fullHash, 'hex'), contentBuffer])), and use the result as fullHash.
Until all calculations are complete, get fullHash
String
No
size
File size for instant upload: Files with size >= 1M can achieve instant upload.
String
No
labels
File Tag List
String Array
No
category
Customized File Categories
String
No
localCreationTime
File creation time
String
No
localModificationTime
File modification time
String
No

Response

Response code

Upload task created successfully, back HTTP 201 Created.
beginningHash matches the instant upload file, return HTTP 202 Accepted.
fullHash matches the instant upload file, return HTTP 200 OK.

Response Body

application/json
Response body example (when it does not meet the instant upload condition):
{
"domain": "examplebucket-1250000000.cos.ap-beijing.myqcloud.com",
"path": "/",
"form": {
"key": "smh3ixxx/xxx.csv",
"acl": "default",
"Content-Type": "image/jpeg",
"x-cos-security-token": "1dleQZoBrm4i5UKcV1ovQM4f63aE3Lda5exxx",
"policy": "eyJleHBpcmF0aW9uIjoixxx",
"q-sign-algorithm": "sha1",
"q-ak": "AKID4w3Z468lCB3JJ4et11DHP-nx9Iw3UgcWS0TlAPTPs1n-Ka-rxxxxxxxxxxxCAZF",
"q-key-time": "1754292918;1754293518",
"q-signature": "6eddafb2fcce90ea548xxxxxxxx1374635aa502d"
},
"confirmKey": "6bdfd20dfb104848f5899e4bfa09331b6e7fccac9c879149xxxxxxxxxxxxxxxx",
"expiration": "2021-07-24T10:34:32.000Z",
"availableDomainNum":1
}
Response body field description:
Response Parameters
Description
Type
domain
Domain name during actual file upload
String
path
URL path during actual file upload, fixed as "/" in form upload
String
form
Other fields that require specifying during actual upload besides the file field. These fields should be before the file field.
String
confirmKey
Parameters for confirming file upload completion
String Array
expiration
Upload information valid period. Exceeds validity period will become invalid. Call this API again to get new upload parameters.
String
availableDomainNum
Number of available domains
Int
Response body example (when beginningHash matches the instant upload condition): return 202 with an empty response body.
Response body example (when fully meeting the instant upload condition):
{
"path": [
"test.xlsx"
],
"name": "test.xlsx",
"type": "file",
"creationTime": "2022-04-08T08:44:59.000Z",
"modificationTime": "2022-04-08T08:44:59.000Z",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"size": "2811086",
"eTag": "\\"b581c674266a2b0ff16a9505b4c52300\\"",
"crc64": "16293198345556339838",
"metaData": {},
"isOverwritten": false,
"previewByDoc": true,
"previewByCI": true,
"previewAsIcon": false,
"fileType": "excel"
}
Response body field description:
Response Parameters
Description
Type
path
If it is an array of strings, it indicates the final file path. The last element in the array represents the final file name, and the other elements represent each first-level directory name. Because files with the same name may exist and be renamed automatically, the final path here may not equal the specified path when uploading started.
If it is null, it means that the directory where the file resides or a certain parent directory has been deleted, and the file can no longer be accessed.
String Array
name
Final file name
String
type
File type
String
creationTime
The time when the file is uploaded for the first time
String Array
modificationTime
Last overwrite time of the file
String
contentType
media type
String
size
File size.
String
eTag
File eTag
String
crc64
File CRC64-ECMA182 check value
String
metaData
metadata, this field does not exist if there is no metadata
String
isOverwritten
Whether file overwrite occurs during file upload
Boolean
previewByDoc
Whether WPS can preview
Boolean
previewByCI
Whether Wanxiang can preview
Boolean
previewAsIcon
Use preview image as icon
Boolean
fileType
File type: Excel, PowerPoint
String

Error Codes

This request operation has no special error messages. For common error messages, see Error Codes.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백