erlangyawsnitrogen

Nitrogen - File upload


I can easily upload a file using Nitrogen's #upload{} element, it works great.

However, I am using client side Javascript to create an html file upload form (not using #upload{} tag in Nitrogen .erl file), and not able to get it to work.

Any ideas on how to approach this?

EDIT: I am using Nitrogen on top of Yaws.


Solution

  • You can use the element_upload.erl file as reference for how to interface with files uploaded using a standard html form.

    Basically, you'll need to get the request bridge from the context, then get the list of files from the request bridge.

    Req = wf_context:request_bridge(),
    UploadedFiles = Req:post_files(),
    

    The uploadedFiles is a list of #sb_uploaded_file records, with the attributes original_name, and temp_file. You can see the details in the simple_bridge header

    From there, you can copy the files elsewhere, or do whatever you need to do with them.

    Edit: The uploaded file interface has been improved in simple_bridge and no longer requires including the header file, instead recommending using the sb_uploaded_file module for interfacing with the uploaded files.