Comments (11)
单个传有问题么?
发自我的 iPhone
在 2014年6月8日,下午2:50,Chen Wei [email protected] 写道:
我要上传一个文件夹的图片到微信服务器,遍历文件夹然后循环对每个文件进行uploadMedia操作,但是返回
{ errcode: 40001, errmsg: 'invalid credential' }
初步猜测是异步的问题,可能微信服务器对特定的access_token一次只能调用一次上传接口。现在不知如何解决。请问有什么方法?谢谢—
Reply to this email directly or view it on GitHub.
from wechat.
单个传没问题。是不是异步的问题?
在 2014年6月9日,上午1:04,Jackson Tian [email protected] 写道:
单个传有问题么?
发自我的 iPhone
在 2014年6月8日,下午2:50,Chen Wei [email protected] 写道:
我要上传一个文件夹的图片到微信服务器,遍历文件夹然后循环对每个文件进行uploadMedia操作,但是返回
{ errcode: 40001, errmsg: 'invalid credential' }
初步猜测是异步的问题,可能微信服务器对特定的access_token一次只能调用一次上传接口。现在不知如何解决。请问有什么方法?谢谢—
Reply to this email directly or view it on GitHub.
—
Reply to this email directly or view it on GitHub.
from wechat.
肯定不是的,能否把代码share出来看看问题。
在 2014年6月9日,上午7:06,Chen Wei [email protected] 写道:
单个传没问题。是不是异步的问题?
在 2014年6月9日,上午1:04,Jackson Tian [email protected] 写道:
单个传有问题么?
发自我的 iPhone
在 2014年6月8日,下午2:50,Chen Wei [email protected] 写道:
我要上传一个文件夹的图片到微信服务器,遍历文件夹然后循环对每个文件进行uploadMedia操作,但是返回
{ errcode: 40001, errmsg: 'invalid credential' }
初步猜测是异步的问题,可能微信服务器对特定的access_token一次只能调用一次上传接口。现在不知如何解决。请问有什么方法?谢谢—
Reply to this email directly or view it on GitHub.
—
Reply to this email directly or view it on GitHub.—
Reply to this email directly or view it on GitHub.
from wechat.
我用coffeescript写的,用到了七牛云存储,client是七牛的客户端。我先从七牛上把图片下下来再传到微信上,代码如下
fs = require 'fs'
http = require 'http'
qn = require 'qn'
async = require 'async'
wechat = require 'wechat'
api = new wechat.API settings.appid, settings.appsecret
client = qn.create qnconf
basedir = 'imageqn/'
client.list '/', (err, result) ->
items = result.items
qnbase = 'http://xbkspace.qiniudn.com/'
async.eachSeries items, (i, cb) ->
filename = i.key
mimeType = i.mimeType
if /^image/.test mimeType
url = qnbase + filename
dest = basedir + filename + '.jpg'
download url, dest, ->
uploadToWechat dest, 'image'
cb()
download = (url, dest, callback) ->
file = fs.createWriteStream dest
request = http.get url, (response) ->
response.pipe file
file.on 'finish', -> file.close(callback)
mediaToday = 'media_today.txt'
uploadToWechat = (filepath, type) ->
api.uploadMedia filepath, type, (err, result) ->
if err then console.log err
fs.appendFile mediaToday, result.media_id + '\n', (err) ->
转成javascript如下
var api, async, basedir, bucket, client, download, fs, http, mediaToday, qn, qnconf, settings, token, uploadToWechat, wechat;
fs = require('fs');
http = require('http');
qn = require('qn');
async = require('async');
wechat = require('wechat');
api = new wechat.API(settings.appid, settings.appsecret);
client = qn.create(qnconf);
basedir = 'imageqn/';
client.list('/', function(err, result) {
var items, qnbase;
items = result.items;
qnbase = 'http://xbkspace.qiniudn.com/';
return async.eachSeries(items, function(i, cb) {
var dest, filename, mimeType, url;
filename = i.key;
mimeType = i.mimeType;
if (/^image/.test(mimeType)) {
url = qnbase + filename;
dest = basedir + filename + '.jpg';
return download(url, dest, function() {
uploadToWechat(dest, 'image');
return cb();
});
}
});
});
download = function(url, dest, callback) {
var file, request;
file = fs.createWriteStream(dest);
return request = http.get(url, function(response) {
response.pipe(file);
return file.on('finish', function() {
return file.close(callback);
});
});
};
mediaToday = 'media_today.txt';
uploadToWechat = function(filepath, type) {
return api.uploadMedia(filepath, type, function(err, result) {
if (err) {
console.log(err);
}
return fs.appendFile(mediaToday, result.media_id + '\n', function(err) {});
});
};
from wechat.
你再抛错误的地方,把当前路径也打印出来。看看是不是某些特殊文件导致的。
在 2014年6月9日,上午10:22,Chen Wei [email protected] 写道:
我用coffeescript写的,用到了七牛云存储,client是七牛的客户端。我先从七牛上把图片下下来再传到微信上,代码如下
fs = require 'fs'
http = require 'http'
qn = require 'qn'
async = require 'async'
wechat = require 'wechat'api = new wechat.API settings.appid, settings.appsecret
client = qn.create qnconf
basedir = 'imageqn/'client.list '/', (err, result) ->
items = result.items
qnbase = 'http://xbkspace.qiniudn.com/'
async.eachSeries items, (i, cb) ->
filename = i.key
mimeType = i.mimeType
if /^image/.test mimeType
url = qnbase + filename
dest = basedir + filename + '.jpg'
download url, dest, ->
uploadToWechat dest, 'image'
cb()download = (url, dest, callback) ->
file = fs.createWriteStream dest
request = http.get url, (response) ->
response.pipe file
file.on 'finish', -> file.close(callback)mediaToday = 'media_today.txt'
uploadToWechat = (filepath, type) ->
api.uploadMedia filepath, type, (err, result) ->
if err then console.log err
fs.appendFile mediaToday, result.media_id + '\n', (err) ->
转成javascript如下var api, async, basedir, bucket, client, download, fs, http, mediaToday, qn, qnconf, settings, token, uploadToWechat, wechat;
fs = require('fs');
http = require('http');
qn = require('qn');
async = require('async');
wechat = require('wechat');api = new wechat.API(settings.appid, settings.appsecret);
client = qn.create(qnconf);basedir = 'imageqn/';
client.list('/', function(err, result) {
var items, qnbase;
items = result.items;
qnbase = 'http://xbkspace.qiniudn.com/';
return async.eachSeries(items, function(i, cb) {
var dest, filename, mimeType, url;
filename = i.key;
mimeType = i.mimeType;
if (/^image/.test(mimeType)) {
url = qnbase + filename;
dest = basedir + filename + '.jpg';
return download(url, dest, function() {
uploadToWechat(dest, 'image');
return cb();
});
}
});
});download = function(url, dest, callback) {
var file, request;
file = fs.createWriteStream(dest);
return request = http.get(url, function(response) {
response.pipe(file);
return file.on('finish', function() {
return file.close(callback);
});
});
};mediaToday = 'media_today.txt';
uploadToWechat = function(filepath, type) {
return api.uploadMedia(filepath, type, function(err, result) {
if (err) {
console.log(err);
}
return fs.appendFile(mediaToday, result.media_id + '\n', function(err) {});
});
};
—
Reply to this email directly or view it on GitHub.
from wechat.
当前路径打出来是用
fs.realpathSync('.');
吗?
还有我不知道是哪里抛错误。批量上传的时候并不是所有的上传都抛错误,比如一个文件夹下有十来张图片,用上面的代码上传的时候可能会有一两张抛40001,也可能某一次执行一张图也没抛错误,不确定性很大。
from wechat.
出错的时候把图片路径打印出来。
在 2014年6月9日,上午10:39,Chen Wei [email protected] 写道:
当前路径打出来是用
fs.realpathSync('.');
吗?还有我不知道是哪里抛错误。批量上传的时候并不是所有的上传都抛错误,比如一个文件夹下有十来张图片,用上面的代码上传的时候可能会有一两张抛40001,也可能某一次执行一张图也没抛错误,不确定性很大。
—
Reply to this email directly or view it on GitHub.
from wechat.
刚刚试了几次错误没重现出来,可能昨天微信服务器不稳定也有可能。等错误重现了我再来
from wechat.
ok。那我先关issue了,你发现后再reopen吧
from wechat.
初步猜测是异步的问题,可能微信服务器对特定的access_token一次只能调用一次上传接口。现在不知如何解决。请问有什么方法?谢谢
问下 你是不是用了cluster?
from wechat.
没有。我就是在本地调的,一个进程,没用集群。
在 2014年6月24日,下午10:17,Jackson Tian [email protected] 写道:
初步猜测是异步的问题,可能微信服务器对特定的access_token一次只能调用一次上传接口。现在不知如何解决。请问有什么方法?谢谢
问下 你是不是用了cluster?
—
Reply to this email directly or view it on GitHub.
from wechat.
Related Issues (20)
- 自动回复消息可否支持回复多条信息? HOT 1
- 我小程序客服消息校验能通过,回复不显示 HOT 2
- 解析xml报错 HOT 2
- 可以同时给用户发送两条信息吗 HOT 1
- 如何做到不回复 HOT 1
- 可以支持小程序客服接口吗 HOT 1
- 在消息安全模式下接收用户信息报错 BadMessageError: Non-whitespace before first tag HOT 2
- 公众号自动回复后可以转发消息吗
- require('nodemailer')之后服务器无法正常工作 HOT 1
- res.reply回复消息会触发connect-redis在redis存一条session记录 HOT 1
- session没过期,调用req.reply还会新生成一条session
- 文档的链接打不开了,貌似是域名过期了
- 如何实现回复一条文字+图片?
- 如何自动回复两条图文?
- Is this API dead? HOT 2
- 找到了一个个人号API 推给大伙https://wkteam.gitbook.io/api/
- 有没有typescript版本呢?
- eggjs能用这个库吗?
- 如何优雅的关闭WXSession支持
- wechaty 无法回复图片消息
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wechat.