-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues on file upload. #6
Comments
I draft the changing code below: r = request.post
url : "#{api_binary}/media/upload?access_token=#{access_token}&type=#{type}"
json : true
, (err, res) ->
return callback err if err
callback null, res.body
form = r.form()
form.append('media', if typeof media == 'string' then fs.createReadStream(media) else media) However, the server just return {"errcode":41005,"errmsg":"media data missing"} and ignore the form data. I don't know how to send a correct request to upload a file. Is there anything wrong? |
The The request generated by For now, I can only remember when the last time I investigated on this issue, I believe it's not my responsibility to have For the more popular wechat module, the authors made a self made module formstream, I dare not to do that. |
I know that the API just accept file. Actually I want to upload an image from a stream instead of a file but it didn't work at present. I compared the request generated from |
If If your goal is a quick fix, why not turn to the aforementioned node module BTW: What did you use to analyze and compare |
I used |
I got the answer. Wechat server expect the form-data part ended with a |
good point. a little trick will do. var media = fs.createReadStream(file);
request.post({
url: url,
json: true,
formData: { media: media, nonce: ''}
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
cb(false, body);
} else {
cb(true, {errorMessage: body});
}
}); |
I found that the code was using curl to upload multimedia file. It broke the application on Windows because of the absence of curl. Besides the issue on Windows, another problem is that it could leverage the native data pipeline on Node.js . It limits the data source to local files.
The text was updated successfully, but these errors were encountered: