Shun Miyazawa 11 месяцев назад
Родитель
Сommit
e5c9712cdb
2 измененных файлов с 5 добавлено и 0 удалено
  1. 1 0
      apps/app/src/server/routes/apiv3/attachment.js
  2. 4 0
      apps/app/src/server/service/attachment.js

+ 1 - 0
apps/app/src/server/routes/apiv3/attachment.js

@@ -341,6 +341,7 @@ module.exports = (crowi) => {
    */
    */
   router.post('/', accessTokenParser, loginRequiredStrictly, excludeReadOnlyUser, uploads.single('file'),
   router.post('/', accessTokenParser, loginRequiredStrictly, excludeReadOnlyUser, uploads.single('file'),
     validator.retrieveAddAttachment, apiV3FormValidator, addActivity,
     validator.retrieveAddAttachment, apiV3FormValidator, addActivity,
+    // Removed autoReap middleware to use file data in asynchronous processes. Instead, implemented file deletion after asynchronous processes complete
     async(req, res) => {
     async(req, res) => {
 
 
       const pageId = req.body.page_id;
       const pageId = req.body.page_id;

+ 4 - 0
apps/app/src/server/service/attachment.js

@@ -50,6 +50,10 @@ class AttachmentService {
       await fileUploadService.uploadAttachment(createReadStream(file.path), attachment);
       await fileUploadService.uploadAttachment(createReadStream(file.path), attachment);
       await attachment.save();
       await attachment.save();
 
 
+      //  Creates a new stream for each operation instead of reusing the original stream.
+      //  REASON: Node.js Readable streams cannot be reused after consumption.
+      //  When a stream is piped or consumed, its internal state changes and the data pointers
+      //  are advanced to the end, making it impossible to read the same data again.
       let fileStreamForAttachedHandler;
       let fileStreamForAttachedHandler;
       if (this.attachHandlers.length !== 0) {
       if (this.attachHandlers.length !== 0) {
         fileStreamForAttachedHandler = createReadStream(file.path);
         fileStreamForAttachedHandler = createReadStream(file.path);