Closed gowridev closed 3 years ago
@gowridev hi there.
Formidable already returns a streams (erm, sort of - it inherits EventEmitter and has some more methods, but yea i believe it would pass the isStream
check). I'm not familiar with pkgcloud
so what method you thinking to use?
var form = new formidable.IncomingForm({ some: 'options' })
form.once('error', console.log)
form.parse(req)
@gowridev Monkey patch will help. An example to upload file to swift:
form.on('fileBegin', function (name, file) {
file.on('error', function(err) {
form._error(err)
})
file.open = function () {
const self = this
this._writeStream = Swift.upload({
container: 'private-tmp',
remote: [require('path').basename(this.path), this.name].join('_'),
contentType: this.type
})
this._writeStream.on('error', function(err) {
self.emit('error', err)
})
}
file.end = function (cb) {
var self = this;
if (self.hash) {
self.hash = self.hash.digest('hex');
}
this._writeStream.on('success', function(pkgcloudFileInstance) {
// do something to attach pkgcloud file instance properties to formidable file instance
//
// and then
self.emit('end')
cb()
})
this._writeStream.end()
}
})
Use fileWriteStreamHandler option,
How to stream media file to pkgcloud package. Pkgcloud only accepts stream data. Could you please sare an example. How to formidable can used with pkgcloud (for media files)