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> 
Felipe Pereira
  • 11,410
  • 4
  • 41
  • 45
  • Have you tried to use the Chrome inspector to see what HTTP code it's returning, both in desktop and mobile? It sounds like it's returning a redirect, and it's a matter of how the client handles it (client code?). In principle, behaviour should be the same for the same HTTP request, unless you're using the user-agent as conditional somewhere! – Alberto Rico Dec 09 '14 at 17:35
  • Not using a the user-agent as a conditional anywhere. Using bootstrap but only media queries for screen size adjustments. Same HTML regardless of platform. Should I post the form? Its literally just one input for a file and a submit button. – user3261403 Dec 09 '14 at 17:39
  • In that case, every time you submit the form, it should reload the page, as normal behaviour. Try debugging the network requests, using the inspector, and compare both results! – Alberto Rico Dec 09 '14 at 17:43
  • It does, which is what I want, but when the form is reloaded from mobile the image has not been uploaded. When the form is submitted from desktop the image has been uploaded. – user3261403 Dec 09 '14 at 17:46
  • Could you show the code for your upload form? – srquinn Dec 09 '14 at 17:49
  • I can't see a fault in the code, so I can only think that the difference lies on a different file is being uploaded from each platform. Have you tried using the same file from each? That should narrow down the problem. – Alberto Rico Dec 09 '14 at 17:51
  • Jibsales I added the form to the post. Alberto- I have been trying the same images and different with no success. Thank you both for your time. It's appreciated. – user3261403 Dec 09 '14 at 18:07
  • Did you take a look at the network requests like Alberto suggested? – Laura Dec 10 '14 at 09:15

0 Answers0