0

File Uploads in Mojito

Hello,

Can anyone know the way for uploading files in Mojito ?? is there any inbuilt mojito mechanism rather using YUI file uploads ??

thanks,

by
3 Replies
  • Hi Ashish,

    Mojito uses express underneath. "req.files" contain information about the files uploaded. There are few articles/blog posts that go into the details. One of them is http://www.hacksparrow.com/handle-file-uploads-in-express-node-js.html

    From Mojito, within a controller, you can get access to req.files like this:
    index: function(ac) {
    var req = ac.http.getRequest();
    var files = req.files;
    ... your code to copy over the files...
    }
    Hope that helps!

    - Raj
    0
  • Hello Raj,

    Thanks a lot for your help.. it really worth for me... now only problem i facing it with Error i getting is 

    Error: ENOENT, rename '/tmp/33f512f5e0f24393aa69a90a7831b748'...

    following is my code...

                   var req = ac.http.getRequest();
      var files = req.files;
    var fs = require('fs');
      var tmp_path = req.files.thumbnail.path;
            // set where the file should actually exists - in this case it is in the "images" directory
            var target_path = '/static/flickr/uploads/' + req.files.thumbnail.name;
            console.log('target_path='+target_path);
            // move the file from the temporary location to the intended location
            fs.rename(tmp_path, target_path, function(err) {
                if (err) throw err;
                // delete the temporary file, so that the explicitly set temporary upload dir does not get filled with unwanted files
                fs.unlink(tmp_path, function() {
                    if (err) throw err;
                    res.send('File uploaded to: ' + target_path + ' - ' + req.files.thumbnail.size + ' bytes');
                });
            });

    i got error at line fs.rename(tmp_path, target_path, function(err) {......

    please suggest me for the same.. where can be a problem ?? is it in path defining or tmp directory ???

    thanks,
    0
  • Hello Raj,

    issue has been resolved.. its path defining issue...

    anyways thanks for ur help...

    - Ashish
    0

Recent Posts

in Yahoo! Mojito