Giter Club home page Giter Club logo

Comments (11)

JacksonTian avatar JacksonTian commented on August 24, 2024

单个传有问题么?

发自我的 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.

chenweiyj avatar chenweiyj commented on August 24, 2024

单个传没问题。是不是异步的问题?

在 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.

JacksonTian avatar JacksonTian commented on August 24, 2024

肯定不是的,能否把代码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.

chenweiyj avatar chenweiyj commented on August 24, 2024

我用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.

JacksonTian avatar JacksonTian commented on August 24, 2024

你再抛错误的地方,把当前路径也打印出来。看看是不是某些特殊文件导致的。

在 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.

chenweiyj avatar chenweiyj commented on August 24, 2024

当前路径打出来是用

fs.realpathSync('.');

吗?

还有我不知道是哪里抛错误。批量上传的时候并不是所有的上传都抛错误,比如一个文件夹下有十来张图片,用上面的代码上传的时候可能会有一两张抛40001,也可能某一次执行一张图也没抛错误,不确定性很大。

from wechat.

JacksonTian avatar JacksonTian commented on August 24, 2024

出错的时候把图片路径打印出来。

在 2014年6月9日,上午10:39,Chen Wei [email protected] 写道:

当前路径打出来是用

fs.realpathSync('.');
吗?

还有我不知道是哪里抛错误。批量上传的时候并不是所有的上传都抛错误,比如一个文件夹下有十来张图片,用上面的代码上传的时候可能会有一两张抛40001,也可能某一次执行一张图也没抛错误,不确定性很大。


Reply to this email directly or view it on GitHub.

from wechat.

chenweiyj avatar chenweiyj commented on August 24, 2024

刚刚试了几次错误没重现出来,可能昨天微信服务器不稳定也有可能。等错误重现了我再来

from wechat.

JacksonTian avatar JacksonTian commented on August 24, 2024

ok。那我先关issue了,你发现后再reopen吧

from wechat.

JacksonTian avatar JacksonTian commented on August 24, 2024

初步猜测是异步的问题,可能微信服务器对特定的access_token一次只能调用一次上传接口。现在不知如何解决。请问有什么方法?谢谢

问下 你是不是用了cluster?

from wechat.

chenweiyj avatar chenweiyj commented on August 24, 2024

没有。我就是在本地调的,一个进程,没用集群。

在 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.