Skip to content

Instantly share code, notes, and snippets.

@Sk-OmarFaruque
Created September 15, 2017 07:32
Show Gist options
  • Save Sk-OmarFaruque/35cc363f11b7e85ddf430dd6bbdf0d98 to your computer and use it in GitHub Desktop.
Save Sk-OmarFaruque/35cc363f11b7e85ddf430dd6bbdf0d98 to your computer and use it in GitHub Desktop.
//unique number by date
new Date().valueOf()
//file upload with rename
let body = ctx.request.body
let imagename = ctx.params.image
let image = body.files.file
var path = require('path')
const fs = require('fs');
let ext = path.extname(image.name)
image.name = `${imagename}_${ext}`
fs.createReadStream(image.path).pipe(fs.createWriteStream(path.join(__dirname,'../../public/uploads',image.name)));
ctx.body = image.name
} catch (e){
ctx.body = {e}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment