node.js - Upload zip files to service for user download -
i have express (node.js) application creates mp3 files user , stores them in folder on server.
the server's file structure looks this:
data/ id#/ song1.mp3 song2.mp3 song3.mp3 id#/ song1.mp3 song2.mp3 song3.mp3 ... i want create zip files , download links folder , email users zip file. each folder named using id# , corresponds user.
i want use external service (such s3) store , handle downloads of files.
how zip files , send them service , create download links? services should into?
you can use child_process module run zip command in background (this example if you're on linux, can modify suit windows)
this handles zip process, can respond link download file:
var exec = require('child_process').exec; var currentworkingdirectory = '/data', // folder contains sub folders of id#/ foldertozip = 'id123123', // subfolder name id#, e.g. id123123 tmpfolderforzips = '/tmp/', // folder store zip files in execstring = "zip -r " + tmpfolderforzips + foldertozip + ".zip " + foldertozip; // tidy string put console.log(execstring); var child = exec(execstring, { cwd: currentworkingdirectory }); child.on('error', function(err) { console.log(err); }) child.on('close', function() { // respond download link zip file console.log('done zipping'); }); make sure apt-get install zip
Comments
Post a Comment