note description : "Objects that ..." author : "$Author$" date : "$Date$" revision : "$Revision$" class IMAGE_UPLOADER inherit ANY WSF_ROUTED_SKELETON_SERVICE undefine requires_proxy end WSF_URI_TEMPLATE_HELPER_FOR_ROUTED_SERVICE WSF_NO_PROXY_POLICY WSF_DEFAULT_SERVICE create make feature {NONE} -- Initialization make -- Initialize Current do initialize_router -- To use particular port number (as 9090) with Nino connector -- Uncomment the following line set_service_option ("port", 9090) make_and_launch end setup_router -- Setup router local www: WSF_FILE_SYSTEM_HANDLER do map_uri_template_agent ("/upload{?nb}", agent execute_upload) create www.make (document_root) www.set_directory_index (<<"index.html">>) www.set_not_found_handler (agent execute_not_found) router.handle_with_request_methods ("", www, router.methods_GET) end feature -- Configuration document_root: READABLE_STRING_8 -- Document root to look for files or directories local e: EXECUTION_ENVIRONMENT dn: DIRECTORY_NAME once create e create dn.make_from_string (e.current_working_directory) dn.extend ("htdocs") Result := dn.string if Result [Result.count] = Operating_environment.directory_separator then Result := Result.substring (1, Result.count - 1) end ensure not Result.ends_with (Operating_environment.directory_separator.out) end files_root: READABLE_STRING_8 -- Uploaded files will be stored in `files_root' folder local dn: DIRECTORY_NAME once create dn.make_from_string (document_root) dn.extend ("files") Result := dn.string end feature -- Execution execute_not_found (uri: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE) -- `uri' is not found, redirect to default page do res.redirect_now_with_content (req.script_url ("/"), uri + ": not found.%NRedirection to " + req.script_url ("/"), "text/html") end execute_upload (req: WSF_REQUEST; res: WSF_RESPONSE) -- Upload page is requested, either GET or POST -- On GET display the web form to upload file, by passing ?nb=5 you can upload 5 images -- On POST display the uploaded files local l_body: STRING_8 l_safe_filename: STRING_8 fn: FILE_NAME page: WSF_HTML_PAGE_RESPONSE n: INTEGER do if req.is_request_method ("GET") or else not req.has_uploaded_file then create page.make page.set_title ("EWF: Upload file") page.add_style (req.script_url ("style.css"), "all") create l_body.make_empty page.set_body (l_body) l_body.append ("