如何执行使用强烈抵制媒体POST请求的更新? [英] How to perform an update with media POST request using twit?
本文介绍了如何执行使用强烈抵制媒体POST请求的更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用蠢。更新状态(无介质)工作正常,但 rel=\"nofollow\">更新不工作。结果
这是我的code(与前preSS使用):
I am using twit. Update status(without media) works fine, but update with media is not working.
This is my code (used with express):
//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参数。结果
我应该如何通过发送图像文件媒体[]
?
推荐答案
请确保您的窗体有一个 ENCTYPE =的multipart / form-data的
键,而不是 req.body.img
尝试使用 req.files.img
Make sure your form has a enctype="multipart/form-data"
and instead of req.body.img
try using req.files.img
检查什么类型的输入T.post从媒体参数想,您可以尝试的base64
Check what kind of input T.post wants from the media parameter, you could try base64
例如客户端code:
<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>
例如服务器code:
example server code:
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);
});
});
这篇关于如何执行使用强烈抵制媒体POST请求的更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文