smalltalkpharoseaside

Executing Script after serializeFileUpload


I don't know if it is possible, but I like to show a picture after uploading it into the Library. As soon as I want to cascade the serializeFileUpload I get an error and the method comment also states that serializeFileUpload may be the only callback. My code so far:

html fileUpload
...
id: #fileUpload;
onChange: (html jQuery ajax 
    serializeFileUpload: (html jQuery id: inputString ));
callback: [ :f | self handleNewFile: f] 

Is there a way to have the jQuery replace #fileUpload with the uploaded image?

Thanks

Max

Implementation in JQAjax>>serializeFileUpload:aQuery

    self
    data:
        ((((JSStream on: 'var formdata = new FormData()'),
         ((aQuery copy attributeAt: 'name') assignLocalTo: 'name'),
         (((aQuery property: 0) access: 'files') assignLocalTo: 'files'),
         (JSStream on:'for(i=0;i<files.length;i++) formdata.append(name,files[i])'),
         (JSStream on: 'return formdata')) asFunction) apply: #());
    url: self renderContext actionUrl;
    type: 'POST';
    cache: false;
    processData: false;
    contentType: false

Solution

  • Have you tried to use the ajax onsucces callback?

    (html jQuery ajax
       ...
       onSuccess: ((html jQuery id: #fileUpload) replaceWith: [:r | ... ]))