0

Code works fine on desktop but I think its timing out on mobile. I'm still new to node. Written in nodejs with express and busboy. The code below shows how I'm handling the image posted from the form. On mobile browser loads for a while then just reloads the form. Processes fine on desktop. Has anyone else had this issue? Any ideas what I'm doing wrong?

router.post('/', function (req, res){

  var busboy = new Busboy({ headers: req.headers });

  busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {

    //name the file uploaded  
    var file_name = Math.round(Math.random()*1000) + '.jpg';

    //store the path of the uploaded file
    var saveTo = 'public/images/uploads/' + file_name;

    file.pipe(fs.createWriteStream(saveTo));
  });

  busboy.on('finish', function() {
    res.redirect('back');
  });    

  return req.pipe(busboy);

});

HTML FORM POSTING IMAGE (added from my phone, sorry if it's a little rough)

<form class="form-inline" action="/" enctype="multipart/form-data" method="post"> 
<div class="form-group"> 
<input type="file" id="upload" name="upload"> 
</div> 
<div class="form-group">
<button type="submit" class="btn btn-default">Find</button> 
</div> 
</form> 
4

0 回答 0