|
@@ -78,25 +78,16 @@ module.exports = function(crowi, app) {
|
|
|
fileName = tmpFile.name,
|
|
fileName = tmpFile.name,
|
|
|
fileType = tmpFile.mimetype,
|
|
fileType = tmpFile.mimetype,
|
|
|
fileSize = tmpFile.size,
|
|
fileSize = tmpFile.size,
|
|
|
- filePath = Attachment.createAttachmentFilePath(id, fileName, fileType);
|
|
|
|
|
|
|
+ filePath = Attachment.createAttachmentFilePath(id, fileName, fileType),
|
|
|
|
|
+ tmpFileStream = fs.createReadStream(tmpPath, {flags: 'r', encoding: null, fd: null, mode: '0666', autoClose: true });
|
|
|
|
|
|
|
|
- fileUploader.uploadFile(
|
|
|
|
|
- filePath,
|
|
|
|
|
- fileType,
|
|
|
|
|
- fs.createReadStream(tmpPath, {
|
|
|
|
|
- flags: 'r',
|
|
|
|
|
- encoding: null,
|
|
|
|
|
- fd: null,
|
|
|
|
|
- mode: '0666',
|
|
|
|
|
- autoClose: true
|
|
|
|
|
- }),
|
|
|
|
|
- {}
|
|
|
|
|
- ).then(function(data) {
|
|
|
|
|
- debug('Uploaded data is: ', data);
|
|
|
|
|
-
|
|
|
|
|
- // TODO size
|
|
|
|
|
- Attachment.create(id, req.user, filePath, originalName, fileName, fileType, fileSize)
|
|
|
|
|
|
|
+ return fileUploader.uploadFile(filePath, fileType, tmpFileStream, {})
|
|
|
.then(function(data) {
|
|
.then(function(data) {
|
|
|
|
|
+ debug('Uploaded data is: ', data);
|
|
|
|
|
+
|
|
|
|
|
+ // TODO size
|
|
|
|
|
+ return Attachment.create(id, req.user, filePath, originalName, fileName, fileType, fileSize);
|
|
|
|
|
+ }).then(function(data) {
|
|
|
var imageUrl = fileUploader.generateS3FileUrl(data.filePath);
|
|
var imageUrl = fileUploader.generateS3FileUrl(data.filePath);
|
|
|
return res.json({
|
|
return res.json({
|
|
|
status: true,
|
|
status: true,
|
|
@@ -106,14 +97,13 @@ module.exports = function(crowi, app) {
|
|
|
pageCreated: pageCreated,
|
|
pageCreated: pageCreated,
|
|
|
message: 'Successfully uploaded.',
|
|
message: 'Successfully uploaded.',
|
|
|
});
|
|
});
|
|
|
- }, function (err) {
|
|
|
|
|
|
|
+ }).catch(function (err) {
|
|
|
debug('Error on saving attachment data', err);
|
|
debug('Error on saving attachment data', err);
|
|
|
-
|
|
|
|
|
// @TODO
|
|
// @TODO
|
|
|
// Remove from S3
|
|
// Remove from S3
|
|
|
return res.json({
|
|
return res.json({
|
|
|
status: false,
|
|
status: false,
|
|
|
- message: '',
|
|
|
|
|
|
|
+ message: 'Error while uploading.',
|
|
|
});
|
|
});
|
|
|
}).finally(function() {
|
|
}).finally(function() {
|
|
|
fs.unlink(tmpPath, function (err) {
|
|
fs.unlink(tmpPath, function (err) {
|
|
@@ -121,15 +111,8 @@ module.exports = function(crowi, app) {
|
|
|
debug('Error while deleting tmp file.');
|
|
debug('Error while deleting tmp file.');
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
- }, function(err) {
|
|
|
|
|
- debug('Upload error to S3.', err);
|
|
|
|
|
-
|
|
|
|
|
- return res.json({
|
|
|
|
|
- status: false,
|
|
|
|
|
- message: 'Error while uploading.',
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ ;
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|