{"errcode":41005,"errmsg":"media data missing hint: [anVMtA04733723]"}

通过新增素材接口上传图片文件

这个接口一直取不到文件搞了一下午
用GuzzleHttp

废话不多说直接上代码

    $path = storage_path()."/app/public/upload/". $filename;
    if(!file_exists($path)){
        Log::error('####  file do not exist! at path!'.$path);
        exit(0);
    }
    $access_token = $this->getAccess_token();
    $uploadurl = getenv('WX_UPLOAD_URL');
    $url =$uploadurl.$access_token.'&type=image';
    $client = new GuzzleHttp\Client();
    $img = fopen($path, 'r');
    $res = $client->request('POST', $url, [
        'multipart' => [
            [
                'name'     => 'filename',
                'contents' => $filename
            ],
            [
                'name'     => 'content-type',
                'contents' => 'image/jpg'
            ],
            [
                'name'     => 'filelength',
                'contents' => filesize($path)
            ],
            [
                'name'     => 'media',
                'contents' => $img
            ]
        ]
    ]);

    $body = $res->getBody();
    $callback = json_decode($body->getContents());
    Log::info('####fileUpload'.$body.$url.$img);
BF77825B-A1E1-4198-9B91-83785180A3B9.png

你可能感兴趣的:({"errcode":41005,"errmsg":"media data missing hint: [anVMtA04733723]"})