首页 新闻 会员 周边

'{"errcode":41005,"errmsg":"media data missing"}'

0
悬赏园豆:10 [待解决问题]
上传各类media,一直显示文件丢失的错误'{"errcode":41005,"errmsg":"media data missing"}'。但是文件确定在该路径下面,代码应该也是没有错误的啊。是什么问题呢?大家有没有遇到过呢?
 
public function uploadMedia($aksk) {
        $type = "image";
        $filepath = '@D:\workspace\appidaib9fc427f\angang.jpg';
        $filedata = array (
                "media" =>$filepath
        );
        $url = 'http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token='.$aksk.'&type='.$type;
        $result=$this->https_request($url,$filedata);
        return $result;
    }
public function https_request($url, $data = null) {
        $curl = curl_init ();
        curl_setopt ( $curl, CURLOPT_URL, $url );
        curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, FALSE );
        curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, FALSE );
        if (! empty ( $data )) {
            curl_setopt ( $curl, CURLOPT_POST, 1 );
            curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
        }
        curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
        $output = curl_exec ( $curl );
        curl_close ( $curl );
        return $output;
    }

 

 
gcfranklin的主页 gcfranklin | 初学一级 | 园豆:192
提问于:2015-01-29 14:30
< >
分享
所有回答(4)
0

参考 https://github.com/baoshan/wx/issues/6

Wechat server expect the form-data part ended with a \r\n but node-request or form-data didn't do the trick so the code above will certainly failed. However, if I added an empty form-data entry to the end of the stream, wechat server will continue to read the stream and end the media part correctly. This hack do send some extra data but will not break the present implementation.

在上传的流的最后插入\r\n

dudu | 园豆:30994 (高人七级) | 2015-01-29 14:45

博客园的新闻评论有问题,在新闻列表页面可以看到评论数增加了,但是点击新闻进入新闻内容页面显示的是之前的评论,只有点一下浏览器上的刷新,才会看到新的评论。

支持(1) 反对(0) Launcher | 园豆:45045 (高人七级) | 2015-01-29 16:51

@Launcher: 谢谢反馈!我们查一下这个问题

支持(0) 反对(0) dudu | 园豆:30994 (高人七级) | 2015-01-29 16:57
0

curl_setopt ( $curl, CURLOPT_POSTFIELDSIZE, $len );

Launcher | 园豆:45045 (高人七级) | 2015-01-29 15:45
0

楼主,你的这个问题解决了没有??

 

我也遇到这个问题了。麻烦死了

脆脆的心 | 园豆:202 (菜鸟二级) | 2017-09-27 10:59
0

在cli模式下,使用 curl命令就ok了。
比如切换到要上传的图片同路径下,使用下面的命令,后面的token换成自己的
curl -F media=@teacher.png -F type=image "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=36_iK1v

mt006 | 园豆:204 (菜鸟二级) | 2020-08-18 16:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册