diff --git a/examples/upload_image/src/image_uploader.e b/examples/upload_image/src/image_uploader.e index 87c03aeb..7d35203e 100644 --- a/examples/upload_image/src/image_uploader.e +++ b/examples/upload_image/src/image_uploader.e @@ -43,6 +43,7 @@ feature {NONE} -- Initialization local www: WSF_FILE_SYSTEM_HANDLER do + map_uri_template_agent_with_request_methods ("/upload/{name}{?nb}", agent execute_upload_put, router.methods_put) map_uri_template_agent ("/upload{?nb}", agent execute_upload) create www.make (document_root) @@ -95,7 +96,7 @@ feature -- Execution local l_body: STRING_8 l_safe_filename: STRING_8 - fn: FILE_NAME + fn: PATH page: WSF_HTML_PAGE_RESPONSE n: INTEGER do @@ -114,8 +115,8 @@ feature -- Execution end if attached {WSF_STRING} req.query_parameter ("demo") as p_demo then create fn.make_from_string (document_root) - fn.set_file_name (p_demo.value) - l_body.append ("File:
%N") + fn := fn.extended (p_demo.value) + l_body.append ("File:
%N") end from @@ -131,15 +132,17 @@ feature -- Execution create l_body.make (255) l_body.append ("

EWF: Uploaded files

%N") l_body.append ("") create page.make @@ -158,8 +162,85 @@ feature -- Execution end end + execute_upload_put (req: WSF_REQUEST; res: WSF_RESPONSE) + -- Upload page is requested, PUT + require + is_put_request_method: req.is_put_request_method + local + l_body: STRING_8 + l_safe_filename: detachable READABLE_STRING_32 + fn: PATH + page: WSF_HTML_PAGE_RESPONSE + n: INTEGER + do + create l_body.make (255) + l_body.append ("

EWF: Uploaded files

%N") + l_body.append ("") + + create page.make + page.set_title ("EWF: uploaded image") + page.add_style ("../style.css", "all") + page.set_body (l_body) + res.send (page) + end + + feature {NONE} -- Encoder + new_temporary_output_file (n: detachable READABLE_STRING_8): detachable FILE + local + bp: detachable PATH + d: DIRECTORY + i: INTEGER + do + create bp.make_current + create d.make_with_path (bp) + if not d.exists then + d.recursive_create_dir + end + if n /= Void then + bp := bp.extended ("tmp-download-" + n) + else + bp := bp.extended ("tmp") + end + from + i := 0 + until + Result /= Void or i > 100 + loop + i := i + 1 + create {RAW_FILE} Result.make_with_path (bp.appended ("__" + i.out)) + if Result.exists then + Result := Void + else + Result.open_write + end + end + ensure + Result /= Void implies Result.is_open_write + end + url_encode (s: READABLE_STRING_32): STRING_8 -- URL Encode `s' as Result do