file-cloud-uploader
v0.1.0
Published
file uploader for cloud services
Downloads
25
Readme
file-cloud-uploader
用于服务器端的文件哈希服务
使用的文件哈希包file-hash
可以用于本地文件的哈希考贝 (采用了file-cloud-disk-uploader)
可以用于阿里云oss的文件考贝(采用了file-cloud-alioss-uploader)
可以用于aws的s3的文件考贝(采用了file-cloud-aws-uploader)
可以用于cloudinary的文件考贝(采用了file-cloud-cloudinary-uploader)
安装
$ npm install --save file-cloud-uploader
Usage
var fileCloudUploader = require('file-cloud-uploader');
####移动上传文件到服务器的特定目录
var filename = path.resolve(__dirname, 'assets/a.txt'); //源文件地址
var config = {
dir: path.resolve(__dirname, 'hashed/'), //文件要保存的地址
base: 'http://localhost' //指定文件保存后的域名地址,加上文件名组成可访问的文件地址
};
fileCloudUploader('disk', filename, config, function (data) {
//data.error
//data.path
//data.url
});
####移动上传文件到aliyun oss
var config = {
accessKeyId: process.env.ALIYUN_OSS_ACCESS_KEY_ID,
secretAccessKey: process.env.ALIYUN_OSS_ACCESS_KEY_SECRET,
endpoint: process.env.ALIYUN_OSS_ENDPOINT,
apiVersion: process.env.ALIYUN_OSS_APP_VERSION,
Bucket: process.env.ALIYUN_OSS_BUCKET,
base: process.env.ALIYUN_OSS_BASE
};
var filename = path.resolve(__dirname, 'assets/a.jpg');
fileCloudUploader('oss', filename, config, function (data) {
//data.error
//data.path
//data.url
});
####移动上传文件到aws s3
var called = false;
var config = {
accessKeyId: process.env.AWS_S3_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_S3_ACCESS_KEY_SECRET,
endpoint: process.env.AWS_S3_ENDPOINT,
Bucket: process.env.AWS_S3_BUCKET,
region: process.env.AWS_S3_REGION,
progress: function (/*evt*/) {
called = true;
}
};
var filename = path.resolve(__dirname, 'assets/a.jpg');
fileCloudUploader('s3', filename, config, function (data) {
assert.equal(true, !data.error);
assert.equal(true, typeof data.path === 'string');
assert.equal(true, validator.isURL(data.url));
done();
});
####移动上传文件到cloudinary
var config = {
cloud_name: process.env.FCU_CLOUDINARY_NAME,
api_key: process.env.FCU_CLOUDINARY_API_KEY,
api_secret: process.env.FCU_CLOUDINARY_API_SECRET
};
var filename = path.resolve(__dirname, 'assets/a.jpg');
fileCloudUploader('cloudinary', filename, config, function (data) {
assert.equal(true, !data.error);
assert.equal(true, typeof data.path === 'string');
assert.equal(true, validator.isURL(data.url));
assert.equal(true, validator.isURL(data.secure_url));
done();
});
License
Apache-2.0 © calidion