File upload progress


i´m using Plug.Uploadto upload files.

How can i capture the % to make a progress bar?



if you are asking about client side (js), then this would work fine, assuming you have an Upload controller that accepts post request on “/upload”

function sendFIle(file) {
  var uri = "/upload";
  var xhr = new XMLHttpRequest();
  var fd = new FormData();"POST", uri, true);

  xhr.upload.addEventListener("progress", function(e) {
    if (e.lengthComputable) {
      var percentage = Math.round((e.loaded * 100) /;
  }, false);

  fd.append('myFile', file);

copied from MDN :slight_smile:

1 Like

Thank you. But i don´t see the connection between Plug.upload and this script. I think i need something like session.upload-progress from php in elixir.

AFAIK there is no such feature in current implementation of Plug.Session, and what if you want to store a session(all the session data) in encrypted cookie for example?
So, basically you’ll have to write it… Or using xhr request to send file(s) is another option