Login expired. Please log in again.

Feedback

0/300

Feedback

Submitted successfully

ok

Feedback

Network exception, please try again later

ok

Upload File API

Latest update time:2022.08.04 Release notes

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.

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


Pathparameter is a path parameter.
Queryparameter needs to be passed in the request URL.
Bodyparameter needs to be passed in the request JSON.

2. Request Parameters

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.
Name Variable Name Type Required Description
File name filename string No The file name of the file part uploaded using the form
File type content_type string No Indicates Content-Type of the uploaded file
File content content string No A binary string indicates the overall content of the uploaded file
File meta information meta object Yes Bodycontains the file meta information and is indicated using json, involving two objects: filename and digest
Name Variable Name Type Required Description
File name filename string[1, 256] Yes Indicates the name of the file uploaded by the merchant, which is customized by the merchant and must be suffixed using pdf, jpg, bmp, or png
Example:verify.pdf
File digest digest string[64, 64] Yes File digest, that is, the value obtained by sha256 calculation of the binary content of the uploaded file
Example:ff3f4036a1164d1ddbad5b3edf9022addb3e1961a54a922708a6c1ffc49e5489

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
Example:b6a17e2a-1dc4-4376-8630-e73d06490c0d

Return Example

{
  "file_id": "b6a17e2a-1dc4-4376-8630-e73d06490c0d"
}

{
    "appid": "wx7bc98d929da735fe",

  }

									{
										"stock_id": ".NET",
										"limit": 10,
									}

									{
										"stock_id": "Python",
										"stock_creator_mchid": "123456",
										"limit": 10,
									}

5. Request Procedure

5.1. Create a POST method request

For example:

POST https://apihk.mch.weixin.qq.com/v3/global/merchant-storage/file/upload HTTP/1.1

{
    "appid": "wx7bc98d929da735fe",

  }

									{
										"stock_id": ".NET",
										"limit": 10,
									}

									{
										"stock_id": "Python",
										"stock_creator_mchid": "123456",
										"limit": 10,
									}

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:

POST
/v3/global/merchant-storage/file/upload
1566987169           // Timestamp
12ced2db6f0193dda91ba86224ea1cd8   // Random number
{"filename": "file1.pdf", "sha256": "hjkahkjsjkfsjk78687dhjahdajhk"} 

5.3.Add the HTTP head:

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

5.4.Add a body:

// 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).

5.5.Send request

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--

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




    Page Navigation

About  WeChat  Pay

Powered By Tencent & Tenpay Copyright©

2005-2024 Tenpay All Rights Reserved.

Contact Us
Wechat Pay Global

WeChat Pay Global

置顶