Creating a File and Obtaining the URL for File Upload
Function
You can create a file and obtain the URL for file upload.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions. For details about the required permissions, see Permissions Policies and Supported Actions.
URI
POST /v1/{project_id}/files
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Project ID. For details about how to obtain the project ID, see Obtaining a Project ID. |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
X-Auth-Token |
No |
String |
User token. This parameter is mandatory when token authentication is used. You can obtain the token by calling the IAM API used to obtain a user token. Value of X-Subject-Token in the response header. |
|
Authorization |
No |
String |
Authentication information. This parameter is mandatory for AK/SK authentication. |
|
X-Sdk-Date |
No |
String |
Time when the request is sent. This parameter is mandatory for AK/SK authentication. The format is YYYYMMDD'T'HHMMSS'Z'. |
|
X-App-UserId |
No |
String |
Third-party user ID, which does not allow Chinese characters. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
file_name |
Yes |
String |
Details: File name. Constraints: It is case-insensitive. Options: The value contains 1 to 256 characters. Default value: N/A |
|
file_md5 |
Yes |
String |
Definition MD5 value of the file content. Base64-encoded 128-bit MD5 digest of the message according to RFC 1864. For details about how to obtain the MD5 value, see Generating the MD5 Value of File Content Using Java Code. Constraints N/A Range The value contains 24 characters. Default Value N/A |
|
file_size |
Yes |
Long |
Details: Total size of a file. Constraints: Up to 5 GB Default value: N/A Value range: 1~5368709120 |
|
file_type |
Yes |
String |
Details: File type Constraints: N/A Options: The value contains 1 to 64 characters. Default value: File name extension. |
|
asset_id |
Yes |
String |
Details: Asset ID of the platform. Constraints: N/A Options: The value contains 1 to 64 characters. Default value: N/A |
|
asset_file_category |
Yes |
String |
Definition File category in an asset. Each asset type contains different file categories.
NOTE:
Constraints An asset can have only one main file. Range The value contains 1 to 128 characters. Default Value N/A |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
X-Request-Id |
String |
Request ID. |
|
Parameter |
Type |
Description |
|---|---|---|
|
file_id |
String |
File ID. |
|
upload_url |
String |
URL for file upload. The validity period is 24 hours.
NOTE:
If the file type is GIF, set Content-Type to image/gif. If the file type is JPEG or JPG, set Content-Type to image/jpeg. If the file type is PNG, set Content-Type to image/png. If the file type is MP4, set Content-Type to video/mp4. If the file type is MP3, set Content-Type to audio/mp3. If the file type is WAV, set Content-Type to audio/wav. For other file types, set Content-Type to application/octet-stream. |
Status code: 400
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. |
|
error_msg |
String |
Error description. |
Status code: 401
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. |
|
error_msg |
String |
Error description. |
Status code: 500
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. |
|
error_msg |
String |
Error description. |
Example Requests
POST https://{endpoint}/v1/6a6a1f8354f64dd9b9a614def7b59d83/files
{
"file_name" : "1.png",
"file_md5" : "n58IG6hfM7vqI4K0vnWpog==",
"file_size" : 1048576,
"file_type" : "png",
"asset_id" : "8cb2f48a2cb006154794741933421100",
"asset_file_category" : "MAIN"
}
Example Responses
Status code: 200
Successful.
{
"file_id" : "b2f8a9e9c39b6dc7ed4c0cfd67366c6a",
"upload_url" : "https://{endpoint}:443/0d697589d98091f12f92c0073501cd79/8cb2f48a2cb006154794741933421100/b2f8a9e9c39b6dc7ed4c0cfd67366c6a.jpg?AccessKeyId=XCQKTA8IWQPCAUQS4SDA&Expires=1671154644&Signature=vXxiJTO239WZcG8sniotTe9qOc4%3D"
}
Status code: 400
Parameters error, including the error code and its description.
{
"error_code" : "MSS.00000003",
"error_msg" : "Invalid parameter"
}
Status code: 401
Authentication is not performed or fails.
{
"error_code" : "MSS.00000001",
"error_msg" : "Unauthorized"
}
Status code: 500
Internal service error.
{
"error_code" : "MSS.00000004",
"error_msg" : "Internal Error"
}
Status Codes
|
Status Code |
Description |
|---|---|
|
200 |
Successful. |
|
400 |
Parameters error, including the error code and its description. |
|
401 |
Authentication is not performed or fails. |
|
500 |
Internal service error. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot