1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Improve the Promise of copyImage

This commit is contained in:
asmsuechan
2017-03-10 20:33:11 -08:00
parent b6eddf0821
commit aae2bddd32
2 changed files with 20 additions and 15 deletions

View File

@@ -15,13 +15,19 @@ function copyImage (filePath, storageKey) {
return Promise.reject(e)
}
//return resolveStorageData(targetStorage)
const inputImage = fs.createReadStream(filePath)
const imageName = path.basename(filePath)
sander.mkdirSync(`${targetStorage.path}/images`)
const outputImage = fs.createWriteStream(path.join(targetStorage.path, 'images', imageName))
inputImage.pipe(outputImage)
return new Promise((resolve, reject) => {
try {
const inputImage = fs.createReadStream(filePath)
const imageName = path.basename(filePath)
sander.mkdirSync(`${targetStorage.path}/images`)
const outputImage = fs.createWriteStream(path.join(targetStorage.path, 'images', imageName))
inputImage.pipe(outputImage)
resolve(`${encodeURI(targetStorage.path)}/images/${encodeURI(imageName)}`)
}
catch(e) {
return reject(e)
}
})
}
module.exports = copyImage