跳转到内容
返回官网

图片上传到图片空间

图片上传到图片空间

一、请求参数

请求URL:

POST https://kf.fw199.com/gateway/pdd/goods/file/space/image/upload

一(一)、基础参数

参数名类型必须说明
appidString必填合作伙伴AppId
timestampString必填当前时间戳
seller_nickString必填拼多多账号, 非店铺名称
signString必填如何计算生成见示例代码

一(二)、业务参数

参数接口参数类型是否必填说明
fileFile与img_url 2选1标准的http file上传,字段为file
img_urlSTRING与file 2选1如果img_url不为空,优先使用img_url

二、请求示例代码

Java

二(一)、上传本地文件

@Test
public void PddGoodsImageUploadRequestByFile() throws Exception {
String seller_nick = Config.PddSellerNick;
//业务参数
Map<String, Object> data = new HashMap<String, Object>();
data.put("appid", Config.AppId);
data.put("seller_nick", seller_nick);
Long timestamp = System.currentTimeMillis() / 1000;
data.put("timestamp", timestamp.toString());
String filePath = "/Users/miller/Downloads/千里马logo.jpg";
data.put("sign", Utils.SignObject(data,Config.AppSecret));
String resp = doHttpRequest(Config.PddFileSpaceImageUploadUrl, data,filePath);
System.out.println(resp);
}
}

二(二)、通过url上传文件

给定图片url上传图片文件到图片空间。

@Test
public void PddGoodsImageUploadRequestByUrl() throws Exception {
String seller_nick = Config.PddSellerNick;
//业务参数
Map<String, Object> data = new HashMap<String, Object>();
data.put("appid", Config.AppId);
data.put("seller_nick", seller_nick);
Long timestamp = System.currentTimeMillis() / 1000;
data.put("timestamp", timestamp.toString());
data.put("img_url","https://cbu01.alicdn.com/img/ibank/O1CN0177fW3T1J4b843MbF0_!!3482710975-0-cib.jpg" );
data.put("sign", Utils.SignObject(data,Config.AppSecret));
String resp = doHttpRequest(Config.PddFileSpaceImageUploadUrl, data,"");
System.out.println(resp);
}

二(三)、上传文件的http请求示例

private String doHttpRequest(String url , Map<String, Object> data, String filePath){
String result ="";
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
System.out.println("请求Url:" +url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
for (Map.Entry<String, Object> entry : data.entrySet()) {
builder.addTextBody(entry.getKey(), entry.getValue().toString(), ContentType.create("text/plain", "UTF-8")); // 添加其他字段
}
// 如果有文件上传
if (!"".equals(filePath)) {
builder.addBinaryBody("file", new File(filePath), ContentType.DEFAULT_BINARY, new File(filePath).getName()); // 添加文件
}
// 设置请求体
HttpEntity entity = builder.build();
httpPost.setEntity(entity);
//发起POST请求
try {
HttpResponse httpResponse = httpclient.execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
result = EntityUtils.toString(httpResponse.getEntity());
} else {
result = ("doPost Error Response: " + httpResponse.getStatusLine().toString());
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}

三、返回结果

返回结果如下 。

{
"code": 0,
"data": {
"file_id": 64518234124,
"url": "https://img.pddpic.com/garner-api-open/2025-08-09/3f0e14b51f3e99bd9abd0fdcbf7bea66.jpg"
},
"message": "ok"
}

说明: code为0表示成功,非0为失败,message会包含失败原因。

四、返回字段说明

参数接口参数类型例子说明
file_idLONG文件id
urlSTRING上传到图片空间以后的url