skipper-aliyunoss
v0.0.1
Published
A skipper adapter to allow uploading files to Aliyun OSS
Downloads
1
Readme
Aliyun OSS(Open Storage Service) adapter for Skipper
Installation
$ npm install skipper-aliyunoss -save
Options
accessKeyId: "在阿里云OSS申请的 accessKeyId", secretAccessKey: "在阿里云OSS申请的 secretAccessKey", endpoint: 'http://oss-cn-hangzhou.aliyuncs.com',根据你的 oss 实例所在地区选择填入 apiVersion: '2013-10-15' Bucket: "在阿里云OSS申请的Bucket",
Usage
var skipperAliyunOSS = require('skipper-aliyunoss'); var skipperMemory = require('skipper-memory');
var fileAdapter = skipperAliyunOSS({ accessKeyId: 'fPyMxwAG8DrNZ9b2', secretAccessKey: '3xO0RWlT7nzleHVjZCuto7wE7NNVB3', endpoint: 'http://oss-cn-hangzhou.aliyuncs.com', apiVersion: '2013-10-15', Bucket: 'jianjianbao' });
uploadImage: function (req, res) { req.file('image').upload({ // don't allow the total upload size to exceed ~10MB adapter: fileAdapter, maxBytes: 10000000, },function whenDone(err, uploadedFiles) { if (err) { return res.negotiate(err); }
// If no files were uploaded, respond with an error.
if (uploadedFiles.length === 0){
return res.badRequest('No file was uploaded');
}
// Save the "fd" and the url where the image for a Poster can be accessed
Poster.update(req.params.id, {
// Generate a unique URL where the image can be downloaded.
imageUrl: require('util').format('%s/poster/image/%s', sails.getBaseUrl(), req.params.id),
// Grab the first file and use it's `fd` (file descriptor)
imageFd: uploadedFiles[0].fd
})
.exec(function (err){
if (err) return res.negotiate(err);
return res.ok();
});
}); }
License
MIT