managed to upload files: -> choose multiple files -> display them -> move them to ./site/files/uploaded_files

This commit is contained in:
fmurer
2016-01-12 21:36:40 +01:00
parent 7896036165
commit ddb3f9474a
12 changed files with 218 additions and 345 deletions

View File

@@ -1,2 +1,3 @@
port=9090
#port=12345
#verbose=true

View File

@@ -1,254 +0,0 @@
note
description: "file_upload application root class"
date: "$Date$"
revision: "$Revision$"
class
CMS_FILE_UPLOAD
inherit
CMS_MODULE
redefine
install,
initialize,
setup_hooks
end
CMS_HOOK_BLOCK
CMS_HOOK_MENU_SYSTEM_ALTER
-- WSF_ROUTED_URI_TEMPLATE_HELPER
SHARED_EXECUTION_ENVIRONMENT
create
make
feature {NONE} -- Initialization
make
do
name := "file_uploader"
version := "1.0"
description := "Service to upload some files"
package := "file upload"
end
feature -- Access
name: STRING
feature {CMS_API} -- Module Initialization
initialize (api: CMS_API)
-- <Precursor>
do
Precursor (api)
end
feature {CMS_API }-- Module management
install (api: CMS_API)
-- install the module
local
sql: STRING
do
-- create a database table
if attached {CMS_STORAGE_SQL_I} api.storage as l_sql_storage then
if not l_sql_storage.sql_table_exists ("file_upload_table") then
sql := "[
CREATE TABLE file_upload_table(
`id` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL CHECK("id">=0),
`name` VARCHAR(100) NOT NULL,
`uploaded_date` DATE,
`size` INTEGER
);
]"
l_sql_storage.sql_execute_script (sql, Void)
if l_sql_storage.has_error then
api.logger.put_error ("Could not initialize database for file uploader module", generating_type)
end
end
Precursor {CMS_MODULE}(api)
end
end
feature -- Access: router
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
-- <Precursor>
local
www: WSF_FILE_SYSTEM_HANDLER
do
map_uri_template_agent (a_router, "/upload{?nb}", agent execute_upload_handler, void)
create www.make_with_path (document_root)
www.set_directory_index (<<"index.html">>)
www.set_not_found_handler (agent execute_not_found_handler)
a_router.handle("", www, a_router.methods_get)
end
feature -- Hooks
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
do
a_hooks.subscribe_to_menu_system_alter_hook (Current)
a_hooks.subscribe_to_block_hook (Current)
end
block_list: ITERABLE [like {CMS_BLOCK}.name]
do
Result := <<"Uploader info TODO">>
end
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
do
end
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
local
link: CMS_LOCAL_LINK
do
create link.make ("Upload", "/upload")
a_menu_system.primary_menu.extend (link)
end
feature -- Configuration
document_root: PATH
-- Document root to look for files or directories
once
Result := execution_environment.current_working_path.extended ("docs")
end
files_root: PATH
-- Uploaded files will be stored in `files_root' folder
once
Result := document_root.extended ("files")
end
feature -- Handler
execute_not_found_handler (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. %N Redirectioin to" + req.script_url ("/"), "text/html")
end
execute_upload_handler(req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API)
local
body: STRING_8
safe_filename: STRING_8
path: PATH
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 body.make_empty
page.set_body (body)
-- create the body
body.append ("<h1> EWF: Upload files </h1>%N")
body.append ("<form action=%"" + req.script_url ("/upload") + "%" method=%"POST%" enctype=%"multipart/form-data%">%N")
-- tetermine how many files to upload by a query parameter ?nb=number_of_files
if attached {WSF_STRING} req.query_parameter ("nb") as p_nb and then p_nb.is_integer then
n := p_nb.integer_value
else
n := 1
end
-- llist for the number of wanted files a upload button
from
until
n = 0
loop
body.append ("<input type=%"file%" name=%"uploaded_file[]%" size=%"60%"></br> %N")
n := n-1
end
-- set the submit button
body.append ("<button type=%"submit%">UPLOAD</button>%N")
res.send (page)
else
create body.make_empty
body.append ("<h1>EWF: Uploaded files</h1>%N")
body.append ("<ul>%N")
n := 0
across
req.uploaded_files as u_file
loop
body.append ("<li>%N")
body.append ("<div>" + u_file.item.name + "=" + html_encode (u_file.item.filename) + " size=" + u_file.item.size.out + " type" + u_file.item.content_type + "</div> %N")
safe_filename := u_file.item.safe_filename
path := files_root.extended (safe_filename)
-- TODO: list dhe uploaded items
body.append ("</li> %N")
end
body.append ("</ul> %N")
-- create page
create page.make
page.add_style ("../style.css", "all")
page.set_body (body)
res.send (page)
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
feature -- Mapping helper: uri template agent
map_uri_template (a_router: WSF_ROUTER; a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER; rqst_methods: detachable WSF_REQUEST_METHODS)
-- Map `h' as handler for `a_tpl', according to `rqst_methods'.
require
a_tpl_attached: a_tpl /= Void
h_attached: h /= Void
do
a_router.map (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods)
end
map_uri_template_agent (a_router: WSF_ROUTER; a_tpl: READABLE_STRING_8; proc: PROCEDURE [TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_REQUEST_METHODS)
-- Map `proc' as handler for `a_tpl', according to `rqst_methods'.
require
a_tpl_attached: a_tpl /= Void
proc_attached: proc /= Void
do
map_uri_template (a_router, a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods)
end
end

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="file_uploader" uuid="795C88E5-9218-4F35-A985-5501340E2D9D">
<target name="file_uploader">
<root class="CMS_FILE_UPLOAD" feature="make"/>
<option warning="true">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<precompile name="base_pre" location="$ISE_PRECOMP\base-safe.ecf"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="\home\fmurer\Documents\EWF_ROC\ROC\cms-safe.ecf"/>
<library name="cms_model" location="\home\fmurer\Documents\EWF_ROC\ROC\library\model\cms_model-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
<library name="wsf_encoder" location="\home\fmurer\Documents\EWF_ROC\eiffelstudio-src\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
<cluster name="file_uploader" location=".\" recursive="true">
<file_rule>
<exclude>/.svn$</exclude>
<exclude>/CVS$</exclude>
<exclude>/EIFGENs$</exclude>
</file_rule>
</cluster>
</target>
</system>

Binary file not shown.

View File

@@ -1,64 +1,29 @@
<!-- Updated: 12/29/2015 9:02:40.000 PM --><div class="feed">
<!-- Updated: 01/10/2016 12:50:45.000 PM --><div class="feed">
<ul>
<li>
<div class="date"> Jan 07</div>
<a href="https://groups.google.com/d/topic/eiffel-users/NeZjrW4IrYI">RE: [eiffel-users] Book suggestion</a>
<div class="description">I agree with each of the three youve mentioned: 1. Thick-client GUI 2. Browser/Webserver/Web-services 3. Mobile applications (phones/tablets) I will add: RaspberryPi! The RaspberryPi is relatively young and needs Eiffel. I have seen folks ganging these little $5 PCs together to produce</div>
<div class="date"> Jan 11</div>
<a href="https://groups.google.com/d/topic/eiffel-users/mCVwJQ21QBA">SCOOP &amp; Contracts</a>
<div class="description">Recently, I was reading a research paper from a Canadian university talking about applying something like SCOOP to Java. Because Java does not have Design-by-Contract, they wanted to build in a new keyword (like "require") called "await". From the writers point of view, the require contract was</div>
</li>
<li>
<div class="date"> Jan 07</div>
<a href="https://groups.google.com/d/topic/eiffel-users/NeZjrW4IrYI">Book suggestion</a>
<div class="description">What the world needs, besides peace, is a new edition of the excellent book *Windows Programming Made Easy* by Maughan and Simon, rewritten for Vision2. I've looked in vain for an equally thorough reference for Vision2. The Vision2 section at docs.eiffel.com is good as far as it goes, but nowhere</div>
<div class="date"> Jan 11</div>
<a href="https://groups.google.com/d/topic/eiffel-users/7HR-z0DVklU">General Question: Object Persistence Mechanism</a>
<div class="description">NEED: An innate, compiler-known, object persistence mechanism, whereby objects are tracked for version (at design-time), version-updating (at run-time comparative between memory object and persisted object), and attribute change auto-persist. What would be nice is something akin to the Design-by</div>
</li>
<li>
<div class="date"> Jan 06</div>
<a href="https://groups.google.com/d/topic/eiffel-users/uDHIDsjbQX8">Re: [eiffel-users] Easiest way to do type comparisons?</a>
<div class="description">I've been looking at the code. There are around 1,500 lines of code affected, and in fact, a pretty high dependence on using type ids rather than testing types of objects. Fixing this is going to be major surgery, but I have to do something because it's broken every project we have in Eiffel,</div>
<div class="date"> Jan 11</div>
<a href="https://groups.google.com/d/topic/eiffel-users/BouQ6JU-fQ4">RE: [eiffel-users] Solving OOSC 2/E E7.3</a>
<div class="description">In addition to Colin's reply, "is" is no longer used, as it is unnecessary. The functions sqrt and atan are in classes SINGLE_MATH or DOUBLE_MATH which are interfaces to the C library functions defined in math.h. Peter Horan -----Original Message----- From: eiffel...@googlegroups.com</div>
</li>
<li>
<div class="date"> Jan 06</div>
<a href="http://stackoverflow.com/questions/34635913/creating-dynamic-objects-eiffel">Creating dynamic objects (Eiffel)</a>
<div class="description"><p>I have to find a way to create objects dynamically, that means the user can decide how many objects to create once the program starts. What I tried to do is:</p>
<pre><code> if count = 6 then
create player1.player
create player2.player
create player3.player
create player4.player
create player5.player
create player6.player
elseif count &gt; 4 then
create player1.player
create player2.player
create player3.player
create player4.player
create player5.player
elseif count &gt; 3 then
create player1.player
create player2.player
create player3.player
create player4.player
elseif count &gt; 2 then
create player1.player
create player2.player
create player3.player
else
create player1.player
create player2.player
end
</code></pre>
<p>Once the user has choosen the number of players, the variable count gets updated and the feature that creates the objects gets called.</p>
<p>I used this kind of brute force method, instead of a loop, because I need the "names" of the objects, I have to called them again in the program.</p>
<p>Anyways the compiler gives me a VEVI error, variable is not properly set.
Some help?</p></div>
<div class="date"> Jan 11</div>
<a href="https://groups.google.com/d/topic/eiffel-users/BouQ6JU-fQ4">Re: [eiffel-users] Solving OOSC 2/E E7.3</a>
<div class="description">The indexing clause has been replaced by the note clause (just a change of keyword). You might try changing the configuration to use transitional syntax instead of standard syntax. On 11 January 2016 at 09:46, <sagyo1...@gmail.com> wrote: > Hi, everyone. > > I'm reading the japanese version of</div>
</li>
<li>
<div class="date"> Jan 05</div>
<a href="https://groups.google.com/d/topic/eiffel-users/uDHIDsjbQX8">RE: [eiffel-users] Easiest way to do type comparisons?</a>
<div class="description">In the old way, you will get the detachable type ID. In the new way (only available in experimental mode), you will always get an attached type ID. This is why, even if you are increasing the size of your table which should have a minimal impact on performance, it will work now and then. ></div>
<div class="date"> Jan 11</div>
<a href="https://groups.google.com/d/topic/eiffel-users/BouQ6JU-fQ4">Solving OOSC 2/E E7.3</a>
<div class="description">Hi, everyone. I'm reading the japanese version of Object-Oriented Software Construction 2/E. I tried to build the code of "7.5.4 class" in EiffelStudio 15.11 and it raises some build errors. My question is: 1) Is the "indexing description:" description disposed? 2) Is the "function: syntax</div>
</li>
<liv class="nav"><a href="/feed_aggregation/forum">See more ...</a></li>
</ul>

View File

@@ -1,4 +1,4 @@
<!-- Updated: 12/29/2015 9:02:38.000 PM --><div class="feed">
<!-- Updated: 01/10/2016 12:50:45.000 PM --><div class="feed">
<ul>
<li>
<div class="date">2015, Nov 17</div>

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="demo" uuid="3643E657-BCBE-46AA-931B-71EAEA877A18" library_target="demo">
<description>Example/demo for Eiffel ROC CMS library</description>
<target name="common" abstract="true">
<root class="DEMO_CMS_SERVER" feature="make_and_launch"/>
<file_rule>
<exclude>/.svn$</exclude>
<exclude>/CVS$</exclude>
<exclude>/EIFGENs$</exclude>
</file_rule>
<option debug="true" warning="true" full_class_checking="false" is_attached_by_default="true" is_obsolete_routine_type="true" void_safety="all" syntax="transitional">
<debug name="dbglog" enabled="true"/>
</option>
<setting name="concurrency" value="thread"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="..\..\cms-safe.ecf" readonly="false">
<option>
<assertions precondition="true" postcondition="true" supplier_precondition="true"/>
</option>
</library>
<library name="cms_admin_module" location="..\..\modules\admin\admin-safe.ecf" readonly="false"/>
<library name="cms_app_env" location="..\..\library\app_env\app_env-safe.ecf" readonly="false"/>
<library name="cms_auth_module" location="..\..\modules\auth\auth-safe.ecf" readonly="false"/>
<library name="cms_basic_auth_module" location="..\..\modules\basic_auth\basic_auth-safe.ecf" readonly="false"/>
<library name="cms_blog_module" location="..\..\modules\blog\cms_blog_module-safe.ecf" readonly="false"/>
<library name="cms_demo_module" location="modules\demo\cms_demo_module-safe.ecf" readonly="false"/>
<library name="cms_email_service" location="..\..\library\email\email-safe.ecf" readonly="false"/>
<library name="cms_feed_aggregator_module" location="..\..\modules\feed_aggregator\feed_aggregator-safe.ecf" readonly="false"/>
<library name="cms_google_search_module" location="..\..\modules\google_search\google_search-safe.ecf" readonly="false" use_application_options="true"/>
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
<library name="cms_node_module" location="..\..\modules\node\node-safe.ecf" readonly="false"/>
<library name="cms_oauth_20_module" location="..\..\modules\oauth20\oauth20-safe.ecf" readonly="false"/>
<library name="cms_openid_module" location="..\..\modules\openid\openid-safe.ecf" readonly="false"/>
<library name="cms_recent_changes_module" location="..\..\modules\recent_changes\recent_changes-safe.ecf" readonly="false"/>
<library name="cms_session_auth_module" location="..\..\modules\session_auth\cms_session_auth-safe.ecf" readonly="false"/>
<library name="cms_taxnomy_module" location="..\..\modules\taxonomy\taxonomy-safe.ecf" readonly="false"/>
<library name="persistence_sqlite3" location="..\..\library\persistence\sqlite3\sqlite3-safe.ecf" readonly="false">
<option>
<assertions/>
</option>
</library>
<library name="persistence_store_odbc" location="..\..\library\persistence\store_odbc\store_odbc-safe.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
</target>
<target name="demo_any" extends="common">
<setting name="concurrency" value="thread"/>
<library name="any_launcher" location="..\..\launcher\any-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="demo_standalone" extends="common">
<option debug="true">
<debug name="dbglog" enabled="true"/>
</option>
<setting name="concurrency" value="scoop"/>
<variable name="httpd_ssl_disabled" value="true"/>
<library name="file_uploader" location="\home\fmurer\Documents\EWF_ROC\ROC\modules\file_upload\file_uploader.ecf"/>
<library name="standalone_launcher" location="..\..\launcher\standalone-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="demo_standalone_none" extends="demo_standalone">
<setting name="concurrency" value="none"/>
</target>
<target name="demo_standalone_mt" extends="demo_standalone">
<setting name="concurrency" value="thread"/>
</target>
<target name="demo_standalone_scoop" extends="demo_standalone">
<setting name="concurrency" value="scoop"/>
</target>
<target name="demo_cgi" extends="common">
<setting name="concurrency" value="none"/>
<library name="cgi_launcher" location="..\..\launcher\cgi-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="demo_libfcgi" extends="common">
<setting name="concurrency" value="none"/>
<library name="libfcgi_launcher" location="..\..\launcher\libfcgi-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="demo" extends="demo_standalone">
</target>
</system>

View File

@@ -0,0 +1,3 @@
port=9090
#port=12345
#verbose=true

View File

@@ -0,0 +1,15 @@
setlocal
set ROC_CMD=call %~dp0..\..\tools\roc.bat
set ROC_CMS_DIR=%~dp0
%ROC_CMD% install --module ..\..\modules\admin --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\auth --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\basic_auth --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\blog --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\node --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\oauth20 --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\openid --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\recent_changes --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\feed_aggregator --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\google_search --dir %ROC_CMS_DIR%
%ROC_CMD% install --module ..\..\modules\taxonomy --dir %ROC_CMS_DIR%

View File

@@ -18,8 +18,6 @@ inherit
CMS_HOOK_MENU_SYSTEM_ALTER
-- WSF_ROUTED_URI_TEMPLATE_HELPER
SHARED_EXECUTION_ENVIRONMENT
create
@@ -47,7 +45,7 @@ feature {CMS_API} -- Module Initialization
Precursor (api)
end
feature {CMS_API }-- Module management
feature {CMS_API}-- Module management
install (api: CMS_API)
-- install the module
@@ -83,7 +81,7 @@ feature -- Access: router
www: WSF_FILE_SYSTEM_HANDLER
do
map_uri_template_agent (a_router, "/upload{?nb}", agent execute_upload_handler, void)
map_uri_template_agent (a_router, "/upload{?nb}", agent execute_upload, void)
create www.make_with_path (document_root)
www.set_directory_index (<<"index.html">>)
@@ -113,7 +111,7 @@ feature -- Hooks
local
link: CMS_LOCAL_LINK
do
create link.make ("Upload", "/upload")
create link.make ("Upload", "upload/")
a_menu_system.primary_menu.extend (link)
end
@@ -122,13 +120,16 @@ feature -- Configuration
document_root: PATH
-- Document root to look for files or directories
once
Result := execution_environment.current_working_path.extended ("docs")
Result := execution_environment.current_working_path.extended ("site")
end
files_root: PATH
-- Uploaded files will be stored in `files_root' folder
local
tmp: PATH
once
Result := document_root.extended ("files")
tmp := document_root.extended ("files")
Result := tmp.extended ("uploaded_files")
end
feature -- Handler
@@ -139,7 +140,89 @@ feature -- Handler
res.redirect_now_with_content (req.script_url ("/"), uri + ": not found. %N Redirectioin to" + req.script_url ("/"), "text/html")
end
execute_upload_handler(req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API)
execute_upload (req: WSF_REQUEST; res: WSF_RESPONSE)
local
body: STRING_8
answer: STRING_8
file_name: STRING_8
file_path: PATH
page: WSF_HTML_PAGE_RESPONSE
tmp: BOOLEAN
do
if req.is_request_method ("GET") or else not req.has_uploaded_file then
-- create page
create page.make
page.set_title ("EWF: Upload file")
page.add_style (req.script_url ("style.css"), "all")
-- page.set_status_code ({HTTP_STATUS_CODE}.ok)
-- create body
create body.make_empty
body.append ("<h1> EWF: Upload files </h1>%N")
body.append ("<form action=%"" + req.script_url ("/upload") + "%" enctype=%"multipart/form-data%" method=%"POST%" %N")
body.append ("<fieldset> <legend>Upload files</legend> %N")
body.append ("<div><label>File %N")
body.append ("<input name=%"file-name[]%" type=%"file%" multiple %N")
body.append ("</label></div> %N")
body.append ("<fieldset><div><button type=sbmit>Upload</button></div></fieldset> %N")
body.append ("</form>%N")
-- connect the body with the page
page.set_body (body)
-- set response
-- res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type", "text/html"], ["Content-length", body.count.out]>>)
res.send (page)
else
-- create page
create page.make
page.set_title ("Uploaded files")
page.add_style (req.script_url ("style.css"), "all")
-- create answer
create answer.make_empty
answer.append ("<h1>Uploaded Files</h1> %N")
answer.append ("<table> %N")
answer.append ("<tr><th>Filename</th><th>Type</th><th>Size</th></tr>")
across
req.uploaded_files as uf
loop
file_name := uf.item.safe_filename
-- add file to table
answer.append ("<tr>")
answer.append ("<td> %N")
answer.append ("<a href=%"../files/uploaded_files/" + file_name + "%">" + uf.item.filename + "</a> ")
answer.append ("</td>")
answer.append ("<td>")
answer.append (uf.item.content_type)
answer.append ("</td>%N")
answer.append ("<td>")
answer.append (uf.item.size.out + "<22>Bytes")
answer.append ("</td>%N")
answer.append ("</tr>")
-- check if file is already in folder
if not files_root.has_extension (file_name) then
file_path := files_root.extended (file_name)
-- move file to path
tmp := uf.item.move_to(file_path.name)
end
end
answer.append ("</table>%N")
-- connect the body with the page
page.set_body (answer)
-- set response
-- res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type", "text/html"], ["Content-length", answer.count.out]>>)
res.send (page)
end
end
execute_upload_handler(req: WSF_REQUEST; res: WSF_RESPONSE)
local
body: STRING_8
safe_filename: STRING_8
@@ -148,13 +231,13 @@ feature -- Handler
n: INTEGER
do
if req.is_request_method ("GET") or else not req.has_uploaded_file then
-- create page
create page.make
page.set_title ("EWF: Upload file")
page.add_style (req.script_url ("style.css"), "all")
create body.make_empty
page.set_body (body)
-- create the body
create body.make_empty
body.append ("<h1> EWF: Upload files </h1>%N")
body.append ("<form action=%"" + req.script_url ("/upload") + "%" method=%"POST%" enctype=%"multipart/form-data%">%N")
@@ -176,7 +259,7 @@ feature -- Handler
-- set the submit button
body.append ("<button type=%"submit%">UPLOAD</button>%N")
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type", "text/html"], ["Content-length", body.count.out]>>)
res.send (page)
else
create body.make_empty
@@ -204,6 +287,7 @@ feature -- Handler
create page.make
page.add_style ("../style.css", "all")
page.set_body (body)
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type", "text/html"], ["Content-length", body.count.out]>>)
res.send (page)
end
end

View File

@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="file_uploader" uuid="795C88E5-9218-4F35-A985-5501340E2D9D" library_target="file_uploader">
<target name="file_uploader">
<root class="CMS_FILE_UPLOAD" feature="make"/>
<option warning="true">
<!-- <root class="CMS_FILE_UPLOAD" feature="make"/> -->
<root all_classes="true" />
<!-- <option warning="true">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option> -->
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<setting name="console_application" value="true"/>
<!-- <precompile name="base_pre" location="$ISE_PRECOMP\base-safe.ecf"/> -->