Created
September 15, 2017 07:32
-
-
Save Sk-OmarFaruque/35cc363f11b7e85ddf430dd6bbdf0d98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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