[Seaside] Fwd: Rest - Ajax request - build file

Sebastien Audier sebastien.audier at gmail.com
Fri Mar 13 01:21:37 UTC 2015


Hi all,

I work on pharo 2.0 and seaside-REST with ZincServer.

I need to rebuild a file which is uploaded by POST requests through
Seaside-REST but I don't really use WASession.

On javascript layer, I cut the file with this function:

document.querySelector('input[type="file"]').addEventListener('change',
function(e) {  var name = this.files.name;
  var blob = this.files[0];

  const BYTES_PER_CHUNK = 1024 * 1024; // 1MB chunk sizes.
  const SIZE = blob.size;

  var start = 0;
  var end = BYTES_PER_CHUNK;

  while(start < SIZE) {
    upload(name, blob.slice(start, end));

    start = end;
    end = start + BYTES_PER_CHUNK;
  }}, false);

And I send datas with this function:

function upload(aFileName, files) {
  var formData = new *FormData*();

  for (var i = 0, file; file = files[i]; ++i) {
    *formData.append(aFileName, file);*
  }

  var xhr = new XMLHttpRequest();
  xhr.open('POST', '/myPath', true);
  xhr.onload = function(e) { ... };

  xhr.send(*formData*);  // multipart/form-data}


I have a POST method on my handler, but I receive multiple requests.
On this way, I don't have access to the requestContext in order to get the
WAFile in request.
If I don't cut the file, it works and I can store on disk. But not in the
other case.

Of course, my goal is to store the file on disk correctly.

So,
How to get file content of each request ?
How  to rebuild and store the file correctly if the requests aren't ordored
?

Any help ?

Thank's a lot.


-- 
Sébastien AUDIER


<http://www.objectfusion.fr/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20150312/042ca7d3/attachment.htm


More information about the seaside mailing list