question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory storage option is not working.

See original GitHub issue

I am using multer to upload images to my cloudinary account. Since the images will be uploaded to cloud I do not need them to be stored locally in my app. I am using the MemoryStorage option as given in the documentation.

var cloudinary = require('cloudinary');
var multer  = require('multer');
var storage = multer.memoryStorage();
var upload = multer({ storage: storage });
var cloudinaryConfig = require('../config/cloudinary');

router.post('/', upload.single('image'), function(req, res){
    cloudinary.config(cloudinaryConfig.connection);

    cloudinary.uploader.upload(req.file.path,{tags:'basic_sample'},function(err,image){
        if(err){ 
            console.warn('------------------- ERROR: ' + err);
        }
        console.log("* public_id for the uploaded image is generated by Cloudinary's service.");
        console.log("* "+image.public_id);
        console.log("* "+image.url);
    });
});

However while uploading the image is also uploaded to an “uploads” folder. Any idea what the problem is? Thank you.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
abhinav-atmosficommented, Oct 5, 2016

i was able to upload it with memory storage. Cloudinary does not directly upload file buffer, i had to covert the buffer into a datauri.

var Datauri = require('datauri'),
storage = multer.memoryStorage(),
 upload = multer({ storage : storage }).single('image');


exports.uploadImage = function (req, res, next) {
  upload(req,res,function(err) {
    var datauri = new Datauri();
    datauri.format('.png', req.file.buffer);
    cloudinary.uploader.upload(datauri.content,
      function(result) {
        if(result.public_id){
         //res.sendStatus(200)
        }else{
          res.sendStatus(500);
        }
      }
    );
  });
};
4reactions
LinusUcommented, May 7, 2016

Sorry for the delay on this, I think what’s happening is that you already have another multer middleware running before the upload.single('image') one. The memory storage doesn’t provide a req.file.path property, but instead gives you a buffer at req.file.buffer.

Can you show how the router object is being used?


The following small example works for me:

const express = require('express')
const multer = require('multer')

const app = express()
const storage = multer.memoryStorage()
const upload = multer({ storage })

app.post('/', upload.single('image'), (req, res) => {
  console.log('Should be undefined:', req.file.path)
  console.log('Should be the buffer:', req.file.buffer)

  res.send('OK')
})

app.get('/', (req, res) => {
  res.type('text/html').send(`
    <html>
    <head>
      <title>Test upload</title>
    </head>
    <body>
      <form method="post" enctype="multipart/form-data">
        <input type="file" name="image" />
        <input type="submit" />
      </form>
    </body>
  </html>
  `)
})

app.listen(3000, () => console.log('http://localhost:3000/'))
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Insufficient Storage Available Error on Android
6 Ways to Fix "Insufficient Storage Available" on an Android · 1 Resetting Your Apps' Caches · 2 Uninstall Unwanted Apps · 3...
Read more >
[SOLVED] How To Fix Insufficient Storage Available (Android)?
Solution 1: Clear App Cache to Free up Space on Android​​ In general, the lack of working space is probably the main cause...
Read more >
Memory and storage Troubleshooting | T-Mobile REVVL
Clearing app cache can resolve issues regarding poor performing applications due to memory consumption. You can clear app cache and data via the...
Read more >
Internal storage isn't showing on windows - Microsoft Community
The internal storage of my smartphone sony Xperia R1 plus dual is not showing on windows,the SD card is showing on windows but...
Read more >
How To Fix Storage Space Running Out Problem on Android
1. Phones with no option to increase storage space · Open your phone Settings. · Tap on Applications. · This will bring up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found