Giter Site home page Giter Site logo

aliyun-ued / aliyun-sdk-js Goto Github PK

View Code? Open in Web Editor NEW
775.0 775.0 198.0 8.22 MB

阿里云 SDK for Javascript,支持在浏览器和 Nodejs 环境使用,支持大部分阿里云服务。

Home Page: http://www.aliyun.com

JavaScript 100.00%
aliyun cdn ecs javascript mts nodejs openapi oss ots rds sdk slb sls

aliyun-sdk-js's People

Contributors

aleelock avatar bodyno avatar bojoyzhou avatar chunlin-li avatar chylvina avatar daxingplay avatar eldereal avatar goto100 avatar hegar avatar jacksontian avatar jasongao180 avatar jsl9208 avatar liketic avatar luozhang002 avatar mayunlei avatar michelliu avatar neverafraid1 avatar perezyuan avatar peterrao avatar ruder avatar suntoe avatar syaning avatar tanhe123 avatar wangtao0101 avatar xiong-liang avatar yongx avatar yunlei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aliyun-sdk-js's Issues

example of uploading local directory with node-oss-sdk

var ALY = require('aliyun-sdk');
var fs = require('fs');
var walk = require('walk');
var bucketName = 'your bucketName';
var dir = 'your upload dir';

var oss = new ALY.OSS({
  accessKeyId: 'your accessKeyId',
  secretAccessKey: 'your secretAccessKey',
  endpoint: 'http://oss-cn-hangzhou.aliyuncs.com',
  apiVersion: '2013-10-15'
});

var walker  = walk.walk(dir, { followLinks: false });

walker.on('file', function(root, stat, next) {
  var filepath = root + '/' + stat.name;
  var uploadpath = filepath.replace(/^(\.\/|\/)/, '');
  console.log('upload file: ', filepath);
  upload(bucketName, filepath, uploadpath, next);
});
walker.on('end', function(err) {
  if (err) {
    console.log(err);
  } else {
    console.log('upload success!');
  }
});

function upload(bucketName, filepath, filename, callback) {
  fs.readFile(filepath, function (err, data) {
    if (err) {
      console.log('read file err: ', err);
      return;
    }
    oss.putObject({
      Bucket: bucketName,
      Key: filename,
      Body: data,
      CacheControl: 'no-cache',
      ContentDisposition: '',
      ContentEncoding: 'utf-8'
    },
    function (err, data) {
      if (err) {
        callback(err);
        return;
      }
      callback(null, data);
      console.log("save to " + filename);
    });
  });
}

华为手机使用putObject时,status code永远回0。

华为手机使用putObject时,status code永远回0,而且没有错误丢出。
测试时确定图片已经上传(因为可以取得刚上传的图片),经过抓包后服务器有回复200,所以定位应该是sdk的问题。
sdk代码发生在:if (xhr.status === 0) return 0;

OSS putObject 1.5.2 有一定概率出现签名错误.

export class FileStore {
    constructor(public bucket: string) { }

    writeFile(key: string, data: string|Buffer): ThenFail<void> {
        console.log(`uploading file "${key}" (${data.length}bytes)...`);

        return ThenFail
            .invoke<any>(oss, 'putObject', {
                Bucket: this.bucket,
                Key: key,
                Body: data
            })
            .then(() => console.log(`completed uploading file "${key}".`));
    }
}

安装所需的第三方库

说明文档写得过于简单。应该注明运行Sample至少需要xmlbuilder、xml2js、pomelo-protobuf和node_memcached等第三方库。

提示问题

使用 oss.putObject 的时候老是提示 [TypeError: Not a buffer] ,最后发现是 配置名字secretAccessKey写错了,莫名其妙的提示

node-webkit内使用时有bug

node-webkit的node执行上下文中有全局window变量,但没有全局navigator变量,所以lib/services/oss.js第59行会报找不到引用navigator的问题。

请清除 console.log 信息。

作为基础库,是不能够随便打印信息出来的。
如果遇到错误,请直接抛出异常,如果不是,请不要随便打印信息。
如果你们内部测试用了console.log
请在发布时将console.log删除。
谢谢。

deleteObjects出错

在我自己的程序以及samples里删除多个Objects都会报“MissingArgument: Missing Some Required Arguments”的错,单个删除的话倒是没问题

另外源代码里的调试的代码段能不能用debug管理一下,现在是只要有DEBUG的值就会输出调试信息,开发起来有点不方便,如果可以的话我可以帮忙修改

"rm -R" not available

The api for OSS discribes deleteObject and deleteObjects. non of them can delete all files with a specific prefix.

I analyzed how the web on "oss.console.aliyun.com" is doing.
if uses a request to "delete_objects"

it has the following parameter:
bucketName: xxxx-xxxx
location: hangzhou
objects: 0000/sfd/
secToken:235hg5jkh32g45hj235kgj
token:Y9a064218746827134892150fac32e
collina:013#JxEAAgA ....

where "0000/sfd/" is the path or prefix to delete.
but the sdk requires a param Delete that then has a list of Objects to specify the keys to delete.

how should I delete a delete a folder?

SignatureNonce太短导致十分容易碰撞

lib/service_interface/query.js:20: SignatureNonce: Math.round(Math.random() * 1000000)
阿里云API禁止在一段时间之内发出两个SignatureNonce相同请求,而在这里SignatureNonce过短,只有六位数字范围,导致十分容易发生碰撞。

通常建议SignatureNonce使用UUID保证无法在短时间内发生碰撞;

oss 没有api方法

var ALY = require('aliyun-sdk');

var oss = new ALY.OSS({
  "accessKeyId": "...",
  "secretAccessKey": "...",
  // 根据你的 oss 实例所在地区选择填入
  // 杭州:http://oss-cn-hangzhou.aliyuncs.com
  // 北京:http://oss-cn-beijing.aliyuncs.com
  // 青岛:http://oss-cn-qingdao.aliyuncs.com
  // 深圳:http://oss-cn-shenzhen.aliyuncs.com
  // 香港:http://oss-cn-hongkong.aliyuncs.com
  // 注意:如果你是在 ECS 上连接 OSS,可以使用内网地址,速度快,没有带宽限制。
  // 杭州:http://oss-cn-hangzhou-internal.aliyuncs.com
  // 北京:http://oss-cn-beijing-internal.aliyuncs.com
  // 青岛:http://oss-cn-qingdao-internal.aliyuncs.com
  // 深圳:http://oss-cn-shenzhen-internal.aliyuncs.com
  // 香港:http://oss-cn-hongkong-internal.aliyuncs.com
  endpoint: 'http://oss-cn-shenzhen.aliyuncs.com/',
  // 这是 oss sdk 目前支持最新的 api 版本, 不需要修改
  apiVersion: '2015-7-23'
});

oss 没有 createMultipartUpload 方法,同样也没有popObject方法,是按照官方的例子写的。

sdk 不支持 stream 么?

伪代码如下:

    var busboy = new Busboy({ headers: req.headers });
    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
        file.pipe( oss ); //  用stream的形式直接上传
    });
    req.pipe(busboy);

这样的话,用户上传一个比较大的文件,也能够直接pipe到oss上了~~

请问现在支持这种使用方法吗?

@xiong-liang

PutObject这个方法是不是有点太麻烦了

每次putObject都得先读出文件流然后写入,这样是不是太麻烦了,虽然这样扩展性好些,但是是否太复杂了。

var fs = require('fs');

fs.readFile('test.json', function (err, data) {
  if (err) {
    console.log('error:', err);
    return;
  }

  oss.putObject({
      Bucket: 'chylvina',
      Key: 'test.json',
      Body: data,
      AccessControlAllowOrigin: '',
      ContentType: 'text/plain',
      CacheControl: 'no-cache',         // 参考: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
      ContentDisposition: '',           // 参考: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1
      ContentEncoding: 'utf-8',         // 参考: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
      ServerSideEncryption: 'AES256',
      Expires: 60
    },
    function (err, data) {

      if (err) {
        console.log('error:', err);
        return;
      }

      console.log('success:', data);

    });
});

或许这样更好些:

oss.putObject(
     Bucket: 'chylvina',
      Key: 'test.json',
      Path: ''
);

上传文件后返回是ETAG是什么鬼?

{ ETag: '"9BEF661C19BD5C2D7639FB0DA0EE37C7"',
RequestId: '56F124AF8C7624A57CED747D' }

我要的是文件名好不好?
或者至少说明出现了什么状况。
如果是文件重复
那也应该返回一个错误,说明文件重复。
返回ETag跟RequestId有什么意义?

SLS构造protocol buffer数据报错

我使用示例的代码和示例数据发送Log:
`sls.putLogs({

//必选字段

projectName: projectName,

logStoreName: logStoreName,

logGroup: logGroup

}`

但是得到错误
no protos or msg exist!
check msg failed!
这个是pomelo-protobuf 的 encoder.js报出来的。
encoder.js在构造protos时使用的是:

//Get protos from protos map use the route as key

var protos = this.protos[route];

但是putLogs函数传递的键值是"logGroup", sls.js里面proto_json的键值是"message LogGroup"。如果把"message LogGroup"改成"logGroup"就能工作了

1.6.5的客户端版本不能使用oss-js-upload

使用1.6.2版本没有问题。

Exception in delivering result of invoking 'ALYSTSMethods.getToken': MODULE_NOT_FOUND: Could not find API configuration oss-2013-10-15
at s (http://127.0.0.1:3000/aliyun-sdk.js:1:156)
at s (http://127.0.0.1:3000/aliyun-sdk.js:1:122)
at http://127.0.0.1:3000/aliyun-sdk.js:1:313
at Function.defineServiceApi (http://127.0.0.1:3000/aliyun-sdk.js:2619:31)
at getLatestServiceClass (http://127.0.0.1:3000/aliyun-sdk.js:2320:19)
at loadServiceClass (http://127.0.0.1:3000/aliyun-sdk.js:2311:19)
at Service as constructor
at new features.constructor (http://127.0.0.1:3000/aliyun-sdk.js:5218:24)
at new OssUpload (http://127.0.0.1:3000/oss-js-upload.js:53:18)
at http://127.0.0.1:3000/app/client/pages/test-oss.jsx?72b01a828b6073bfbd616a58558c2153b275772e:28:29

OSS怎么设置HttpClient的超时?

在国内测试都还正常,不过把测试用例放在了travis-ci.org上,连接OSS就发现超时了。请问怎么设置OSS超时,谢谢

下面是错误信息
{ [NetworkingError: connect ETIMEDOUT 112.124.219.82:443]
message: 'connect ETIMEDOUT 112.124.219.82:443',
code: 'NetworkingError',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '112.124.219.82',
port: 443,
region: null,
hostname: 'xxx.oss-cn-hangzhou.aliyuncs.com',
retryable: true,
time: Tue Dec 22 2015 08:42:16 GMT+0000 (UTC) }

上传大小为0B的文件引发的node hang

web框架:express
node版本:v4.1.2
触发条件:

  1. 通过oss sdk的putObject上传一个0B的txt文件
  2. 服务端使用了Domain来处理未捕获的异常

详细说明:

  1. 服务端取得上传的文件流后调用oss sdk的putObject,但是因为文件大小为0字节,方法返回了err,错误信息为InvalidParameterType: Expected params.Body to be a string, Buffer, Stream, Blob, or typed array object。并且也触发了putObject的回调函数,logger.error打出了相应的错误信息
file.stream.pipe(concat(function(data){
    this.oss.putObject({
        Bucket: bucket,
        Key: filename,
        Body: data,
        ContentType: file.mimetype,
        AccessControlAllowOrigin: '',
        ServerSideEncryption: 'AES256'
    }, function(err, result){
        if(err) {
            logger.error("put " + filename + " to " + bucket + " in oss failed, err:", err);
            cb(err);
        }
        else{
            ........
        }
    }.bind(this));
}.bind(this)));
  1. 通过domain定义了处理未捕获异常的函数,问题来了,即使上面已经在回调函数中拿到了err,putObject依然会抛出一个未捕获得异常,初步看了下代码,sdk内部会判断是否存在domain,如果存在就会触发下面的函数处理,如果不使用下面的函数则没有任何问题。而且如果使用domain处理,node就会hang在程序的某处,导致所有请求都无法正常处理
exports.catchUncaughtError = function(req, res, next){
    var d = domain.create();
    //监听domain的错误事件
    d.on('error', function (err) {
         logger.error("Uncaught Exception, need reboot server:", err);
         res.status(err.status).json({ErrorCode: xxx, ErrorMessage: xxx})
         d.dispose();
    });

    d.add(req);
    d.add(res);
    d.run(next);
};

疑问:

  1. 为什么已经在putObject的callback中拿到了异常信息,为什么还要作为未捕获异常来处理?
  2. 为什么我自己定义了第2点提到的处理函数后,当前请求会永久性hang住?

InvalidStateError: DOM Exception 11 in old webkit browser

I was testing our website using iOS 7 and encountered the following exception, InvalidStateError: DOM Exception 11.

After some digging, the culprit seems like this line, https://github.com/aliyun-UED/aliyun-sdk-js/blob/master/lib/http/xhr.js#L27.

Based on the answer from http://stackoverflow.com/a/15623060/1361621 and bug report from Webkit https://bugs.webkit.org/show_bug.cgi?id=45994, I would suggest a change on the code by removing this line (https://github.com/aliyun-UED/aliyun-sdk-js/blob/master/lib/http/xhr.js#L27). Any thoughts?

STS生成的signature不匹配

我们正在使用该library试图在server端生成STS token,但是却从STS endpoint得到error说 'Specified signature is not matched with our calculation.'

我使用的代码如下

var ALY = require('aliyun-sdk');

Meteor.methods({
  'oss.getSTSCreds'() {
    const sts = new ALY.STS({
      accessKeyId: "*",
      accessKeySecret: "*",
      endpoint: 'https://sts.aliyuncs.com',
      apiVersion: '2015-04-01'
    });
    const role = 'acs:ram::123456:role/oss';
    const policy = {
      "Statement": [
        {
          "Action": [
            "oss:*"
          ],
          "Effect": "Allow",
          "Resource": [ "acs:oss:*:*:*" ]
        }
      ],
      "Version": "1"
    };
    sts.assumeRole(
      { Action: 'AssumeRole', RoleArn: role, Policy: JSON.stringify(policy), DurationSeconds: 900, RoleSessionName: 'RoleSessionName' },
      (error, result) => {
        console.log(error);
        console.log(result);
      });
  }
});

添加测试说明

目前的测试虽然已经添加,但是并没有如何配置选项与运行测试的说明。
请添加。

如何将OSS中的图片进行缩放?

我尝试使用以下代码获取图片的缩放结果

oss.getObject({
  Bucket:bucket,
  Key:imageName+'@750w'
}, function(err,content){
  //404
});

但是却返回404,console显示url中的@被转码为%40
请问我应该如何正确的使用JS的SDK获取缩放后的图片?

删除某个文件夹下唯一文件,该文件夹也没了?

譬如说:
文件路径: /aaa/bbb/ccc.txt
该路径下除了ccc.txt没有其他文件。即:aaa下只有bbb,bbb下只有ccc.txt文件。
如果我现在把ccc.txt删除了,那么整个路径/aaa/bbb/ccc.txt都没了。= =||
设计如此?

SignatureDoesNotMatch

error: { [SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.]
message: 'The request signature we calculated does not match the signature you provided. Check your key and signing method.',
code: 'SignatureDoesNotMatch',
headers:
{ server: 'AliyunOSS',
date: 'Tue, 15 Dec 2015 04:45:53 GMT',
'content-type': 'application/xml',
'content-length': '1027',
connection: 'close',
'x-oss-request-id': '566F9B013A7B8CC20D7424DB',
'x-oss-server-side-encryption': 'AES256' },
time: Tue Dec 15 2015 12:45:51 GMT+0800 (**标准时间),
statusCode: 403,
retryable: false }

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.