Updated code to remove obsolete call on recent version of json library.

Updated upload_image example to use PATH instead of DIRECTORY_NAME or similar.
Removed unused local variables.
This commit is contained in:
2015-04-07 19:27:30 +02:00
parent b7a12eddaf
commit 881625a0f6
25 changed files with 131 additions and 112 deletions

View File

@@ -21,6 +21,8 @@ inherit
WSF_DEFAULT_SERVICE
SHARED_EXECUTION_ENVIRONMENT
create
make
@@ -46,7 +48,7 @@ feature {NONE} -- Initialization
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)
create www.make_with_path (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)
@@ -54,31 +56,18 @@ feature {NONE} -- Initialization
feature -- Configuration
document_root: READABLE_STRING_8
document_root: PATH
-- 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
Result := execution_environment.current_working_path.extended ("htdocs")
ensure
not Result.ends_with (Operating_environment.directory_separator.out)
not Result.name.ends_with (Operating_environment.directory_separator.out)
end
files_root: READABLE_STRING_8
files_root: PATH
-- 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
Result := document_root.extended ("files")
end
feature -- Execution
@@ -114,8 +103,7 @@ feature -- Execution
n := 1
end
if attached {WSF_STRING} req.query_parameter ("demo") as p_demo then
create fn.make_from_string (document_root)
fn := fn.extended (p_demo.value)
fn := document_root.extended (p_demo.value)
l_body.append ("File: <input type=%"file%" name=%"uploaded_file[]%" size=%"60%" value=%""+ html_encode (fn.name) +"%"></br>%N")
end
@@ -139,9 +127,8 @@ feature -- Execution
n := n + 1
l_body.append ("<li>")
l_body.append ("<div>" + c.item.name + "=" + html_encode (c.item.filename) + " size=" + c.item.size.out + " type=" + c.item.content_type + "</div>")
create fn.make_from_string (files_root)
l_safe_filename := c.item.safe_filename
fn := fn.extended (l_safe_filename)
fn := files_root.extended (l_safe_filename)
if c.item.move_to (fn.name) then
if c.item.content_type.starts_with ("image") then
l_body.append ("%N<a href=%"../files/" + url_encode (l_safe_filename) + "%"><img src=%"../files/"+ l_safe_filename +"%" /></a>")
@@ -187,8 +174,7 @@ feature -- Execution
if attached new_temporary_output_file ("tmp-uploaded-file_" + n.out) as f then
req.read_input_data_into_file (f)
f.close
create fn.make_from_string (files_root)
fn := fn.extended (l_safe_filename)
fn := files_root.extended (l_safe_filename)
f.rename_file (fn.name)
l_body.append ("<li>")
l_body.append ("<div>Input data : size=" + f.count.out + " (" + req.content_length_value.out + ")</div>")