Nino connector:
- fixed issue related to `ready_for_reading' now use the `try_...' variant - for now Nino does not support persistent connection, then we have to respond with "Connection: close" REQUEST_FILE_SYSTEM_HANDLER: - added not_found_handler and access_denied_handler, so that the user can customize related response WSF_REQUEST and WSF_VALUE: - modified how uploaded file are handled, fixed various issues, and added WSF_UPLOADED_FILE (it is a WSF_VALUE) WSF_VALUE: - added change_name (a_name: like name) - added url_encoded_name to other WSF_values WSF_REQUEST: - added `destroy' to perform end of request cleaning (such as deleting temp uploaded files) - renamed `raw_post_data_recorded' as `raw_input_data_recorded', and related feature - do not store the RAW_POST_DATA in meta variable anymore, but in WSF_REQUEST.raw_input_data is asked Added WSF_HTML_PAGE_RESPONSE to help user WSF_REPONSE.redirect_... now use "temp_redirect" as default instead of "moved_permanently" which is specific usage Removed many obsolete features.
This commit is contained in:
BIN
examples/upload_image/htdocs/ewf.jpg
Normal file
BIN
examples/upload_image/htdocs/ewf.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
BIN
examples/upload_image/htdocs/favicon.ico
Normal file
BIN
examples/upload_image/htdocs/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
0
examples/upload_image/htdocs/files/do_not_remove
Normal file
0
examples/upload_image/htdocs/files/do_not_remove
Normal file
10
examples/upload_image/htdocs/index.html
Normal file
10
examples/upload_image/htdocs/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>EWF: demo upload image file</title>
|
||||
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>EWF: demo upload image file</h1>
|
||||
<a href="upload">Click for the demo</a>
|
||||
</body>
|
||||
</html>
|
||||
4
examples/upload_image/htdocs/style.css
Normal file
4
examples/upload_image/htdocs/style.css
Normal file
@@ -0,0 +1,4 @@
|
||||
h1 { border: solid 1px #00f; margin: 5px; padding: 5px; background-color: #009; color: #fff; margin: 10px;}
|
||||
form { border: solid 1px #999; margin: 20px; padding: 10px;}
|
||||
img { width: 60%; }
|
||||
img.hover { width: 100%; }
|
||||
197
examples/upload_image/src/image_uploader.e
Normal file
197
examples/upload_image/src/image_uploader.e
Normal file
@@ -0,0 +1,197 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
IMAGE_UPLOADER
|
||||
|
||||
inherit
|
||||
ANY
|
||||
|
||||
URI_TEMPLATE_ROUTED_SERVICE
|
||||
|
||||
ROUTED_SERVICE_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize Current
|
||||
local
|
||||
s: DEFAULT_SERVICE_LAUNCHER
|
||||
do
|
||||
initialize_router
|
||||
create s.make_and_launch (agent execute)
|
||||
-- Use the following line to use particular port number (as 9090) with Nino connector
|
||||
-- create s.make_and_launch_with_options (agent execute, <<["port", 9090]>>)
|
||||
end
|
||||
|
||||
create_router
|
||||
-- Create router
|
||||
do
|
||||
create router.make (5)
|
||||
end
|
||||
|
||||
setup_router
|
||||
-- Setup router
|
||||
local
|
||||
www: REQUEST_FILE_SYSTEM_HANDLER [REQUEST_URI_TEMPLATE_HANDLER_CONTEXT]
|
||||
do
|
||||
router.map_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.map_with_request_methods ("{/path}{?query}", www, <<"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
|
||||
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_default (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Default request handler if no other are relevant
|
||||
do
|
||||
res.redirect_now_with_content (req.script_url ("/"), "Redirection to " + req.script_url ("/"), "text/html")
|
||||
end
|
||||
|
||||
execute_not_found (uri: READABLE_STRING_8; ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; 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 (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; 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 ("<h1>EWF: Upload image file</h1>%N")
|
||||
l_body.append ("<form action=%""+ req.script_url ("/upload") +"%" method=%"POST%" enctype=%"multipart/form-data%">%N")
|
||||
if attached ctx.string_query_parameter ("nb") as p_nb and then p_nb.is_integer then
|
||||
n := p_nb.to_integer
|
||||
else
|
||||
n := 1
|
||||
end
|
||||
if attached ctx.string_query_parameter ("demo") as p_demo then
|
||||
create fn.make_from_string (document_root)
|
||||
fn.set_file_name (p_demo.string)
|
||||
l_body.append ("File: <input type=%"file%" name=%"uploaded_file[]%" size=%"60%" value=%""+ html_encode (fn.string) +"%"></br>%N")
|
||||
end
|
||||
|
||||
from
|
||||
until
|
||||
n = 0
|
||||
loop
|
||||
l_body.append ("File: <input type=%"file%" name=%"uploaded_file[]%" size=%"60%" accept=%"image/*%"></br>%N")
|
||||
n := n - 1
|
||||
end
|
||||
l_body.append (" <input type=%"submit%" value=%"Upload%"/>%N</form>")
|
||||
page.send_to (res)
|
||||
else
|
||||
create l_body.make (255)
|
||||
l_body.append ("<h1>EWF: Uploaded files</h1>%N")
|
||||
l_body.append ("<ul>")
|
||||
across
|
||||
req.uploaded_files as c
|
||||
loop
|
||||
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.set_file_name (l_safe_filename)
|
||||
if c.item.move_to (fn.string) 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>")
|
||||
else
|
||||
l_body.append ("File " + html_encode (c.item.filename) + " is not a supported image<br/>%N")
|
||||
end
|
||||
end
|
||||
l_body.append ("</li>")
|
||||
end
|
||||
l_body.append ("</ul>")
|
||||
|
||||
create page.make
|
||||
page.set_title ("EWF: uploaded image")
|
||||
page.add_style ("../style.css", "all")
|
||||
page.set_body (l_body)
|
||||
page.send_to (res)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Encoder
|
||||
|
||||
url_encode (s: READABLE_STRING_32): STRING_8
|
||||
-- URL Encode `s' as Result
|
||||
do
|
||||
Result := url_encoder.encoded_string (s)
|
||||
end
|
||||
|
||||
url_encoder: URL_ENCODER
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
html_encode (s: READABLE_STRING_32): STRING_8
|
||||
-- HTML Encode `s' as Result
|
||||
do
|
||||
Result := html_encoder.encoded_string (s)
|
||||
end
|
||||
|
||||
html_encoder: HTML_ENCODER
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2012, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
31
examples/upload_image/upload_image-safe.ecf
Normal file
31
examples/upload_image/upload_image-safe.ecf
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="upload_image" uuid="F2400BE8-D8EB-48EB-B4E4-5D4377062A7F">
|
||||
<target name="upload_image">
|
||||
<root class="IMAGE_UPLOADER" feature="make"/>
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/\.git$</exclude>
|
||||
<exclude>/\.svn$</exclude>
|
||||
</file_rule>
|
||||
<option debug="true" warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional">
|
||||
<debug name="nino" enabled="true"/>
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="connector_nino" location="..\..\library\server\ewsgi\connectors\nino\nino-safe.ecf" readonly="false" use_application_options="true">
|
||||
<option>
|
||||
<assertions precondition="true" check="true" invariant="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
</library>
|
||||
<library name="default_nino" location="..\..\library\server\wsf\default\nino-safe.ecf" readonly="false" use_application_options="true"/>
|
||||
<library name="encoder" location="..\..\library\text\encoder\encoder-safe.ecf" readonly="false"/>
|
||||
<library name="http" location="..\..\library\protocol\http\http-safe.ecf" readonly="false"/>
|
||||
<library name="router" location="..\..\library\server\request\router\router-safe.ecf" readonly="false"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<library name="uri_template" location="..\..\library\protocol\uri_template\uri_template-safe.ecf" readonly="false"/>
|
||||
<library name="wsf" location="..\..\library\server\wsf\wsf-safe.ecf" readonly="false" use_application_options="true"/>
|
||||
<cluster name="src" location="src\" recursive="true">
|
||||
</cluster>
|
||||
</target>
|
||||
</system>
|
||||
Reference in New Issue
Block a user