I wanted to create a zip file and upload it without writing a temporary file to disk like so:
gulp.task( 'zip-upload', function() {
return gulp.src( '**/*', { cwd: 'out/', cwdbase: true } )
.pipe( zip( 'file.zip' ) )
.pipe( request.put( 'https://myurl.com' ) );
});
But it throws an error:
http.js:853
throw new TypeError('first argument must be a string or Buffer');
TypeError: first argument must be a string or Buffer
at ClientRequest.OutgoingMessage.write (http.js:853:11)
at Request.write (.../node_modules/request/request.js:1315:25)
I ended up solving it by using two tasks, but this is not ideal:
gulp.task( 'zip', function() {
return gulp.src( '**/*', { cwd: 'out/', cwdbase: true } )
.pipe( zip( 'file.zip' ) )
.pipe( gulp.dest( './' ) );
});
gulp.task( 'upload', [ 'zip' ], function() {
fs.createReadStream('file.zip').pipe( request.put( 'https://myurl.com' ) );
});
Is it possible to use something like the first approach with gulp?
Dependencies:
npm install gulp-zip request
Thanks.
It looks like gulp-buffer should be able to fix your issue:
Install gulp-buffer and add it to your gulpfile, after that insert the buffer between your zip call and the request.
gulp.task( 'zip-upload', function() {
return gulp.src( '**/*', { cwd: 'out/', cwdbase: true } )
.pipe( zip( 'file.zip' ) )
.pipe( buffer() )
.pipe( request.put( 'https://myurl.com' ) );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With