|
@@ -46,41 +46,33 @@ module.exports = function(crowi, app) {
|
|
|
// 'url': imageUrl,
|
|
// 'url': imageUrl,
|
|
|
// 'message': '',
|
|
// 'message': '',
|
|
|
//});
|
|
//});
|
|
|
|
|
+ var tmpFileStream = fs.createReadStream(tmpPath, {flags: 'r', encoding: null, fd: null, mode: '0666', autoClose: true });
|
|
|
|
|
+
|
|
|
|
|
+ fileUploader.uploadFile(filePath, tmpFile.mimetype, tmpFileStream, {})
|
|
|
|
|
+ .then(function(data) {
|
|
|
|
|
+ var imageUrl = fileUploader.generateS3FileUrl(filePath);
|
|
|
|
|
+ req.user.updateImage(imageUrl, function(err, data) {
|
|
|
|
|
+ fs.unlink(tmpPath, function (err) {
|
|
|
|
|
+ // エラー自体は無視
|
|
|
|
|
+ if (err) {
|
|
|
|
|
+ debug('Error while deleting tmp file.', err);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- fileUploader.uploadFile(
|
|
|
|
|
- filePath,
|
|
|
|
|
- tmpFile.mimetype,
|
|
|
|
|
- fs.createReadStream(tmpPath, {
|
|
|
|
|
- flags: 'r',
|
|
|
|
|
- encoding: null,
|
|
|
|
|
- fd: null,
|
|
|
|
|
- mode: '0666',
|
|
|
|
|
- autoClose: true
|
|
|
|
|
- }),
|
|
|
|
|
- {},
|
|
|
|
|
- function(err, data) {
|
|
|
|
|
- if (err) {
|
|
|
|
|
return res.json({
|
|
return res.json({
|
|
|
- 'status': false,
|
|
|
|
|
- 'message': 'Error while uploading to ',
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- var imageUrl = fileUploader.generateS3FileUrl(filePath);
|
|
|
|
|
- req.user.updateImage(imageUrl, function(err, data) {
|
|
|
|
|
- fs.unlink(tmpPath, function (err) {
|
|
|
|
|
- // エラー自体は無視
|
|
|
|
|
- if (err) {
|
|
|
|
|
- console.log('Error while deleting tmp file.');
|
|
|
|
|
- }
|
|
|
|
|
- return res.json({
|
|
|
|
|
- 'status': true,
|
|
|
|
|
- 'url': imageUrl,
|
|
|
|
|
- 'message': '',
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ 'status': true,
|
|
|
|
|
+ 'url': imageUrl,
|
|
|
|
|
+ 'message': '',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ }).catch(function (err) {
|
|
|
|
|
+ debug('Uploading error', err);
|
|
|
|
|
+
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ 'status': false,
|
|
|
|
|
+ 'message': 'Error while uploading to ',
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
actions.index = function(req, res) {
|
|
actions.index = function(req, res) {
|