UNPKG

dl

Version:

DreamLab Libs

57 lines (47 loc) 1.61 kB
var Core = require("core"), Class = Core.Class, Event = Core.event.Event, ErrorEvent = Core.event.ErrorEvent, crypto = Core.crypto, knox = require('knox'); var DriverAbstract = require("./DriverAbstract.js").DriverAbstract; /** * @class S3 */ var S3 = function () { this.Extends = DriverAbstract; /* this._client = null; this._credentialKey = null; this._credentialData = null; */ this.initialize = function (application, configuration) { this.parent(application, configuration); this._client = null; this._credentialKey = null; this._credentialData = null; this._client = knox.createClient({ key: this._configuration.ACCESS_KEY, secret: this._configuration.SECRET_KEY, bucket: this._configuration.buckets.BUCKET_TEMP //endpoint: 's3-eu-west-1.amazonaws.com' }); }; this.set = function (data, name) { var that = this; var req = this._client.put(crypto.md5(data), { 'Content-Length': data.length, 'Content-Type': 'application/octet-stream' }); req.on('response', function(res){ if (200 == res.statusCode) { that.registerUrl(req.url, name); } else { that.dispatchEvent(new ErrorEvent(DriverAbstract.Event.ERROR, {res: res, req:req}, -5, 'S3 Error')); } }); req.end(data); }; }; S3 = new Class( new S3() ); exports.S3 = S3;