aliyun-ued / aliyun-sdk-js Goto Github PK
View Code? Open in Web Editor NEW阿里云 SDK for Javascript,支持在浏览器和 Nodejs 环境使用,支持大部分阿里云服务。
Home Page: http://www.aliyun.com
阿里云 SDK for Javascript,支持在浏览器和 Nodejs 环境使用,支持大部分阿里云服务。
Home Page: http://www.aliyun.com
https://github.com/aliyun-UED/aliyun-sdk-js/blob/master/samples/oss/multipartUpload.js#L16
这行在上传大于内存的文件时, 会报错.
buffer.js:71
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
^
RangeError: Attempt to allocate Buffer larger than maximum size: 0x3fffffff bytes
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,而且没有错误丢出。
测试时确定图片已经上传(因为可以取得刚上传的图片),经过抓包后服务器有回复200,所以定位应该是sdk的问题。
sdk代码发生在:if (xhr.status === 0) return 0;
如果没有人在实现,我来实现,然后PR吧
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等第三方库。
如题,求aliyun线上地址
请问什么时候支持DNS API
RT
使用 oss.putObject 的时候老是提示 [TypeError: Not a buffer] ,最后发现是 配置名字secretAccessKey写错了,莫名其妙的提示
node-webkit的node执行上下文中有全局window
变量,但没有全局navigator
变量,所以lib/services/oss.js
第59行会报找不到引用navigator
的问题。
作为基础库,是不能够随便打印信息出来的。
如果遇到错误,请直接抛出异常,如果不是,请不要随便打印信息。
如果你们内部测试用了console.log
请在发布时将console.log删除。
谢谢。
现在跑的nsq。希望官方早点出啊。
之前说9月份出:链接
不过,刚才要用到
在我自己的程序以及samples里删除多个Objects都会报“MissingArgument: Missing Some Required Arguments”的错,单个删除的话倒是没问题
另外源代码里的调试的代码段能不能用debug管理一下,现在是只要有DEBUG的值就会输出调试信息,开发起来有点不方便,如果可以的话我可以帮忙修改
oss的putObject怎么用?.好像没找到详细的例子和api
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?
如题……
lib/service_interface/query.js:20: SignatureNonce: Math.round(Math.random() * 1000000)
阿里云API禁止在一段时间之内发出两个SignatureNonce相同请求,而在这里SignatureNonce过短,只有六位数字范围,导致十分容易发生碰撞。
通常建议SignatureNonce使用UUID保证无法在短时间内发生碰撞;
早上更新了下SDK,发现之前的代码不能跑了,listObjects Delimiter 参数填写'/'提示非法.
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方法,是按照官方的例子写的。
{ [NetworkingError: getaddrinfo ENOTFOUND]
hostname: '_/_/**/images.oss-cn-qingdao.aliyuncs.com',
hostname是这样?
在浏览器中oss-js-upload.js文件中报错self.oss.OssUpload is not a function
伪代码如下:
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上了~~
请问现在支持这种使用方法吗?
The request signature does not conform to Aliyun standards
每次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: '"9BEF661C19BD5C2D7639FB0DA0EE37C7"',
RequestId: '56F124AF8C7624A57CED747D' }
我要的是文件名好不好?
或者至少说明出现了什么状况。
如果是文件重复
那也应该返回一个错误,说明文件重复。
返回ETag跟RequestId有什么意义?
目前的测试用例无法在本地跑成功,需要有集成测试证明接口是可靠的。
oss里的例子里面的test.json在哪
{ [InvalidArgument: x-oss-server-side-encryption header is not supported for this operation.]
我使用示例的代码和示例数据发送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"就能工作了
按照 https://github.com/meteormatt/oss-upload-stream实现上传,
怎么实现MD5的文件完整性校验,也就是传到oss里面的文件的完整性问题,
谢谢!
使用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
在国内测试都还正常,不过把测试用例放在了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) }
web框架:express
node版本:v4.1.2
触发条件:
详细说明:
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)));
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);
};
疑问:
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?
期望有官方js sdk实现
我们正在使用该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);
});
}
});
目前的测试虽然已经添加,但是并没有如何配置选项与运行测试的说明。
请添加。
The sample code here doesn't work https://github.com/aliyun-UED/aliyun-sdk-js/blob/master/samples%2Fsts%2Ftest.js
Currently it only supports assumeRole method I think according to https://github.com/aliyun-UED/aliyun-sdk-js/blob/master/apis%2Fsts-2015-04-01.json
Could you better document how to use STS in the SDK?
我尝试使用以下代码获取图片的缩放结果
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都没了。= =||
设计如此?
初始化new ALY.OSS()是否支持传入自定义域名?
目前如果不传bucket会报错Missing required key
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 }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.