Skip to content

Commit a76aed2

Browse files
committed
Fixes #1822
1 parent d2163da commit a76aed2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

browser/main/lib/dataApi/attachmentManagement.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
3939

4040
const targetStorage = findStorage.findStorage(storageKey)
4141

42-
const inputFile = fs.createReadStream(sourceFilePath)
42+
const inputFileStream = fs.createReadStream(sourceFilePath)
4343
let destinationName
4444
if (useRandomName) {
4545
destinationName = `${uniqueSlug()}${path.extname(sourceFilePath)}`
@@ -49,8 +49,10 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
4949
const destinationDir = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
5050
createAttachmentDestinationFolder(targetStorage.path, noteKey)
5151
const outputFile = fs.createWriteStream(path.join(destinationDir, destinationName))
52-
inputFile.pipe(outputFile)
53-
resolve(destinationName)
52+
inputFileStream.pipe(outputFile)
53+
inputFileStream.on('end', () => {
54+
resolve(destinationName)
55+
})
5456
} catch (e) {
5557
return reject(e)
5658
}
@@ -146,7 +148,7 @@ function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem
146148
base64data = reader.result.replace(/^data:image\/png;base64,/, '')
147149
base64data += base64data.replace('+', ' ')
148150
const binaryData = new Buffer(base64data, 'base64').toString('binary')
149-
fs.writeFile(imagePath, binaryData, 'binary')
151+
fs.writeFileSync(imagePath, binaryData, 'binary')
150152
let imageMd = generateAttachmentMarkdown(imageName, imagePath, true)
151153
codeEditor.insertAttachmentMd(imageMd)
152154
}

0 commit comments

Comments
 (0)