yusueketk 7 лет назад
Родитель
Сommit
e6805d3d88
1 измененных файлов с 23 добавлено и 12 удалено
  1. 23 12
      src/server/service/file-uploader/gridfs.js

+ 23 - 12
src/server/service/file-uploader/gridfs.js

@@ -21,6 +21,17 @@ module.exports = function(crowi) {
   // obtain a model
   AttachmentFile= gridfs.model;
 
+  // // delete a file
+  // lib.deleteFile = function (fileId, filePath) {
+  //   debug('File deletion: ' + filePath);
+  //   return new Promise(function (resolve, reject) {
+  //     fileId = 'id';
+  //     AttachmentFile.unlinkById(fileId, function (error, unlinkedAttachment) {
+  //       resolve();
+  //     });
+  //   });
+  // };
+
   // create or save a file
   lib.uploadFile = function (filePath, contentType, fileStream, options) {
     return new Promise(function (resolve, reject) {
@@ -36,20 +47,20 @@ module.exports = function(crowi) {
     });
   };
 
-  // for larger file size
-  // read a file and receive a stream
-  // var stream = Attachment.readById(objectid);
+  for larger file size
+  read a file and receive a stream
+  var stream = Attachment.readById(objectid);
 
-  // for smaller file size
-  // // read a file and receive a buffer
-  // Attachment.readById(objectid, function (error, buffer) {
-  //   debug('Failed to read a file with ' + buffer, error);
-  // });
+  for smaller file size
+  // read a file and receive a buffer
+  Attachment.readById(objectid, function (error, buffer) {
+    debug('Failed to read a file with ' + buffer, error);
+  });
 
-  // // remove file details and its content from gridfs
-  // Attachment.unlinkById(objectid, function (error, unlinkedAttachment) {
-  //   debug('Failed to remove ' + unlinkedAttachment + 'in gridFS', error);
-  // });
+  // remove file details and its content from gridfs
+  Attachment.unlinkById(objectid, function (error, unlinkedAttachment) {
+    debug('Failed to remove ' + unlinkedAttachment + 'in gridFS', error);
+  });
 
   lib.generateUrl = function (filePath) {
     return path.posix.join('/uploads', filePath);