alipay.offline.material.image.upload
Use this interface to upload images or videos, after which, each image or video is then assigned a unique ID. Only with the ID can the image or video be used.
Request
Service address
Environment | HTTPS request URL |
Production environment |
Request parameters
Parameter | Description |
Basic parameter | |
app_id String (32) | A unique ID that is assigned by Alipay to identify an app
|
method String (128) | The interface name
|
format String (40) | Request format. Only JSON is supported.
|
charset String (10) | The charset with which the request data are encoded. UTF-8, GBK, and GB2312 are supported.
|
sign_type String (10) | The signature algorithm used by the merchant to generate the pre-sign string. RSA and RSA2 are supported. RSA2 is preferred.
|
sign String (344) | The signature value. See Signature for details.
|
timestamp String (19) | The time when the request is sent. The format is yyyy-MM-dd HH:mm:ss.
|
version String (3) | The interface version. The value is fixed as 1.0.
|
Business parameter | |
image_type String (8) | Format of the image or video
|
image_name String (128) | Name of the image or video |
image_content Byte_array (5.24288e+06) | Binary data of the image or video. The maximum image file size cannot exceed 5 MB and the maximum video file size cannot exceed 50 MB. |
Response
Parameter | Description |
Basic parameter | |
code String | Gateway return code, which indicates whether the request is accepted by Alipay gateway.
|
msg String | Description of the gateway return code
|
sub_code String | Processing result of the request
|
sub_msg String | Description of the processing result of the request
|
sign String | The signature value. See Signature for details.
|
Business parameter | |
image_id String (32) | The unique ID assigned by Alipay to identify an image or video
|
image_url String (512) | URL of the image or video |
Business error code
Error code | Description | Solution |
INVALID_PARAM | The request parameters are invalid. | Use correct parameters in the request |
SYSTEM_ERROR | System error | Try again later. |
EXCEED_MAX_SIZE | Image size exceeds 5 MB, or video size exceeds 50 MB. | Reduce the file size and retry. |
UNKNOWN_FORMAT | The file format is not supported. | Use only BMP, PNG, JPEG, JPG, and GIF for images. Use only MP4 for videos. |
INVALID_FILE_BYTES | The binary data is not that of an image or video file. | Ensure the binary data is of an image or video file of the supported formats. |
CAPACITY_EXCEEDED | A merchant cannot upload more than 5000 images/videos. | Delete the unnecessary images or videos and retry. |
Sample
Request sample
JAVA
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","app_id","your private_key","json","GBK","alipay_public_key","RSA2");
AlipayOfflineMaterialImageUploadRequest request = new AlipayOfflineMaterialImageUploadRequest();
request.setImageType("jpg or mp4");
request.setImageName("Jack");
FileItem ImageContent = new FileItem(C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg);
request.setImageContent(ImageContent);
request.setImagePid("2088021822217233");
AlipayOfflineMaterialImageUploadResponse response = alipayClient.execute(request);
if(response.isSuccess()){
System.out.println("Call succeeds");
} else {
System.out.println("Call fails");
}
.NET
IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", "app_id", "merchant_private_key", "json", "1.0", "RSA2", "alipay_public_key", "GBK", false);
AlipayOfflineMaterialImageUploadRequest request= new AlipayOfflineMaterialImageUploadRequest() ;
request.ImageType = "jpg or mp4";
request.ImageName = "Jack";
FileItem ImageContent = new FileItem(C:/Downloads/ooopic_963991_7eea1f5426105f9e6069/16365_1271139700.jpg);
request.setImageContent = "-";
request.ImagePid = "2088021822217233";
AlipayOfflineMaterialImageUploadResponse response=client.Execute(request);
Console.WriteLine(response.Body);
PHP
$aop = new AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = 'your app_id';
$aop->rsaPrivateKey = 'Please fill in the developer's private key in a line of string, removing the head, tail, and carriage return';
$aop->alipayrsaPublicKey='Please fill in Alipay public key in a line of string';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='GBK';
$aop->format='json';
$request = new AlipayOfflineMaterialImageUploadRequest ();
$request->setImageType("jpg or mp4");
$request->setImageName("Jack");
$request->setImageContent("@"."Local file path");
$request->setImagePid("2088021822217233");
$result = $aop->execute ( $request);
HTTP request source code
https://openapi.alipay.com/gateway.do?timestamp=2013-01-01 08:08:08&method=alipay.offline.material.image.upload&app_id=2361&sign_type=RSA2&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&version=1.0&image_type=
"jpg or mp4"
&image_name=
"Jack"
&image_pid=
"2088021822217233"
//To ensure a secure communication, verify whether the sign value in the response sample is provided by Ant Financial.
Response sample
JSON
{
"alipay_offline_material_image_upload_response": {
"code": "10000",
"msg": "Success",
"image_id": "hOTQ1lT1TtOjcxGflvnUXgAAACMAAQED",
"image_url": "http://dl.django.t.taobao.com/rest/1.0/image?fileIds=V9rfg69SSimLZg5wDA3yEgAAACMA..."
},
"sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}
XML
<alipay_offline_material_image_upload_response>
<code>10000</code>
<msg>Success</msg> <image_id>hOTQ1lT1TtOjcxGflvnUXgAAACMAAQED</image_id>
<image_url>http://dl.django.t.taobao.com/rest/1.0/image?fileIds=V9rfg69SSimLZg5wDA3yEgAAACMA...</image_url>
</alipay_offline_material_image_upload_response>
Exception sample
JSON
{
"alipay_offline_material_image_upload_response": {
"code": "20000",
"msg": "Service Currently Unavailable",
"sub_code": "isp.unknow-error",
"sub_msg": "System busy"
},
"sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
}