首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用twit对媒体发布请求执行更新?

如何使用twit对媒体发布请求执行更新?
EN

Stack Overflow用户
提问于 2013-09-25 04:17:12
回答 1查看 458关注 0票数 3

我正在使用转转。Update状态(没有媒体)可以正常工作,但是与媒体更新不能工作。

这是我的代码(与express一起使用):

代码语言:javascript
复制
//client side

<form id="tweeter" action='/image' method='POST' >
  <input type="text" name="tw" id="tw" />
  <input type='file' name='img' id='img' /> 
  <input type="submit" value="submit" /> 
</form>


 //server side

app.post('/image',function(req,res){
  var f= "./" +req.body.img;
  console.log(req.body.img);
  T.post('statuses/update_with_media', 
    { status: req.body.tw, media: f }, 
    function(err, reply) {
      console.log('ERROR:' +err);
      console.log('REPLY:' +reply);
    }
  );
});

我得到的错误是‘丢失或无效的url参数’

如何通过media[]发送图像文件?

EN

回答 1

Stack Overflow用户

发布于 2014-01-16 15:59:31

确保您的表单有一个enctype="multipart/form-data",而不是req.body.img,尝试使用req.files.img

从媒体参数中检查T.post想要什么样的输入,可以尝试base64

示例客户端代码:

代码语言:javascript
复制
<form id="tweeter" enctype="multipart/form-data" action='/image' method='POST' >
   <input type="text" name="tw" id="tw" />
   <input type='file' name='img' id='img' /> 
   <input type="submit" value="submit" /> 
</form>

示例服务器代码:

代码语言:javascript
复制
app.post('/image',function(req,res){
    var f = fs.readFileSync(req.files.img.path,'base64');
    T.post('statuses/update_with_media', {status: req.body.tw, media:f}, function(err, reply) {
        console.log('ERROR:'+err);
        console.log('REPLY:'+reply);
    });
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18996140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档