Upload File
Update Time:2025.01.07Some designated merchants of Weixin Pay overseas business need to upload documents. They can use this API to submit these documents and obtain the FileID values required by other business APIs.
1. API Instructions
Applicable to:Common mode Institutional mode
Request URL:https://apihk.mch.weixin.qq.com/v3/global/merchant-storage/file/upload
Request body type:multipart/form-data
Request method:POST
Path parameter is a path parameter.
Query parameter needs to be passed in the request URL.
Body parameter needs to be passed in the request JSON.
2. Request Parameters
Name | Variable Name | Type | Required | Description | |||
---|---|---|---|---|---|---|---|
File information | file | object | Yes | Body performs binary conversion for the file to obtain binary content, which is uploaded in the request body. The file can be in the PDF, JPG, BMP, or PNG format, with a file size not exceeding 5 M. | |||
| |||||||
File meta information | meta | object | Yes | Body contains the file meta information and is indicated using json, involving two objects: filename and digest | |||
|
3. Request Sample of Each Language
---Sample code to be updated---
4. Return Parameters
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
File ID | file_id | string[16, 64] | Yes | File ID returned by WeChat |
Return Example
Normal example
5. Request Procedure
5.1. Create a POST method request
For example:
HTTP
5.2.Add the file data to the request body
5.2.1 How to obtain the file parameters of the file information:
Conduct binary conversion to the file to obtain the binary content and place it in the http.
5.2.2 How to obtain the meta parameters of the file meta information:
The file meta information is indicated using json, involving two objects: filename and digest.
● How to obtain the filename parameter:
The name of the file uploaded by the merchant is determined by the merchant and must be suffixed using pdf, jpg, bmp, or png
● How to obtain the digest parameter:
File digest, that is, the value obtained by sha256 calculation of the binary content of the uploaded file
5.2.3 Signature calculation::
Signature generation
The request body involved in signature calculation is a JSON string of meta:
{"filename": "file1.pdf", "sha256": "hjkahkjsjkfsjk78687dhjahdajhk"}
Example of a string to be signed:
5.3.Add the HTTP head:
5.4.Add a body:
Note:The end of each line of the request packet body needs to contain \r\n (including the blank lines).
5.5.Send request
6. Error Code
Error Codes | Error Message | Description | Solution |
---|---|---|---|
400 | INVALID_REQUEST | The file size of the uploaded file cannot exceed 5 M. Please check the size of the transmitted field (content). | Please replace or compress the file before calling it again. |
400 | INVALID_REQUEST | The value of the uploaded file content calculated by sha256 encryption algorithm is inconsistent with the value of the transmitted field (digest). Please check the calculation method of the transmitted field (digest). | Please refer to the guidelines to check the calculation method of the transmitted field (digest) |
400 | INVALID_REQUEST | The file type of uploaded file is currently not supported | Check whether the transmitted field (content_type) is in pdf, jpg, bmp, or png |