Upload File API
Some 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.
Some 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.
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
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
File information | file | object | Yes | Bodyperforms 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 | Bodycontains the file meta information and is indicated using json, involving two objects: filename and digest |
---Sample code to be updated---
Name | Variable Name | Type | Required | Description |
---|---|---|---|---|
File ID | file_id | string[16, 64] | Yes | File ID returned by WeChat Example:b6a17e2a-1dc4-4376-8630-e73d06490c0d |
{
"file_id": "b6a17e2a-1dc4-4376-8630-e73d06490c0d"
}
For example:
POST https://apihk.mch.weixin.qq.com/v3/global/merchant-storage/file/upload HTTP/1.1
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:
POST
/v3/global/merchant-storage/file/upload
1566987169 // Timestamp
12ced2db6f0193dda91ba86224ea1cd8 // Random number
{"filename": "file1.pdf", "sha256": "hjkahkjsjkfsjk78687dhjahdajhk"}
Content-Type:multipart/form-data.Set to the MIME media type of the object to be uploaded.
Authorization: WECHATPAY2-SHA256-RSA2048 mchid="1900231671",
nonce_str="PCHK6HSOEDTACETP6P3AL7DWPHTBKIAT",timestamp="1567067659",
serial_no="1FB89742D19F2BD30B69948D16DECA0FCB4481EB",
signature="PB6M7+3JL7TSCl5zqD1sdWVypOIEQsD4dgOU+vPiVM6GMRo2qYSWKf8u46i9ZJFhyZTBdZ7SFR+BjDZh6
89hFgN8LZL+QWTvq3cse/FEUFYyOLN7L/2IZX4GA4cWInuJ2MpOhZRMpm+emrcn42gTMKAPNQ7dBLO7ux6MoSuQp69
PW+p1ogmkER68exTVUXYqA5P3vITlWNr++RDy2+ExvB7qVISOKW0vBkxUxN9e7hwUbDwGln170ZXomoO1KpQSbw3f1u
WUCx/IlWJhJIun7rUMtVT+kfijNUqcILtSfE4hWKKVaZn9j5CX8M7aKbbDOFy3SvbSJ3WQgRnRbgog5w=="
Content-Type: multipart/form-data;boundary=boundary
// The content of the body is as follows
--boundary // boundary is a string customized by the merchant
Content-Disposition: form-data; name="meta";
Content-Type: application/json
//There must be a blank line here
{"filename": "file1.pdf", "sha256": "hjkahkjsjkfsjk78687dhjahdajhk"}
--boundary
Content-Disposition: form-data; name="file"; filename="file1.pdf";
Content-Type: application/pdf
//There must be a blank line here
context123 //context123 is the binary content of the file to be uploaded
--boundary--
Note:The end of each line of the request packet body needs to contain \r\n (including the blank lines).
POST /v3/global/merchant-storage/file/upload HTTP/1.1
Host: api.mch.weixin.qq.com
Authorization: WECHATPAY2-SHA256-RSA2048
mchid="1900231671",nonce_str="PCHK6HSOEDTACETP6P3AL7DWPHTBKIAT",
timestamp="1567067659",
serial_no="1FB89742D19F2BD30B69948D16DECA0FCB4481EB",
signature="PB6M7+3JL7TSCl5zqD1sdWVypOIEQsD4dgOU+vPiVM6GMRo2qYSWKf8u46i9ZJFhyZTBdZ7
SFR+BjDZh689hFgN8LZL+QWTvq3cse/FEUFYyOLN7L/2IZX4GA4cWInuJ2MpOhZRMpm+emrcn42gTMKAPN
Q7dBLO7ux6MoSuQp69PW+p1ogmkER68exTVUXYqA5P3vITlWNr++RDy2+ExvB7qVISOKW0vBkxUxN9e
7hwUbDwGln170ZXomoO1KpQSbw3f1uWUCx/IlWJhJIun7rUMtVT+kfijNUqcILtSfE4hWKKVaZn9j5CX8M
7aKbbDOFy3SvbSJ3WQgRnRbgog5w=="
Content-Type: multipart/form-data;boundary=boundary
--boundary
Content-Disposition: form-data; name="meta";
Content-Type: application/json
{"filename": "file1.pdf", "sha256": "hjkahkjsjkfsjk78687dhjahdajhk"}
--boundary
Content-Disposition: form-data; name="file"; filename="file1.pdf";
Content-Type: application/pdf
context123
--boundary--
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 |
Customer Service Tel
Business Development
9:00-18:00
Monday-Friday GMT+8
Technical Support
WeChat Pay Global
ICP证