Shun Miyazawa 10 месяцев назад
Родитель
Сommit
e5c9712cdb

+ 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'),
     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) => {
 
       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 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;
       if (this.attachHandlers.length !== 0) {
         fileStreamForAttachedHandler = createReadStream(file.path);