MailChimp Api,解析图像时出错

MailChimp Api, Error parsing image

错误:

type: http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ title: Invalid Resource status: 400 detail: Error parsing image: Sorry, files with no extension are not allowed. instance: ef9dc203-c04a-48bd-95b4-66c46de26b77

Php代码

    $apikey = GP('mailchimp_api_key');

    $auth       =    base64_encode( 'user:'.$apikey );

    $list = array(

        'name'=>'File Name',
        'file_data'=>'iVBORw....'
        //'file_data'=>'data:image/png;base64,iVBORw....'
 );

    $json_post = json_encode($list);

    $ch = curl_init();

    $curlopt_url = 'https://us18.api.mailchimp.com/3.0/file-manager/files';

    curl_setopt($ch, CURLOPT_URL, $curlopt_url);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.$auth));
    curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/3.0');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_post);

    $result = curl_exec($ch);
    $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    echo "<pre>";
    print_r($result);
    echo "</pre>";

我的问题,我想通过 MailChimp 上传照片 Api。

错误原因是什么?

您需要在代码中为 $list 数组中 name 参数的值设置文件扩展名。扩展名必须与您上传的文件完全相同。

curl --request POST \
--url 'https://usX.api.mailchimp.com/3.0/file-manager/files' \
--user 'anystring:apikey' \
--header 'content-type: application/json' \
--data '{"name": "test.txt", "file_data": "VGhpcyBpcyBhbiBleGFtcGxlIGxpbmUgb2YgdGV4dC4="}' \
--include

File Manager Files