review file upload/download of example 'cl-repl'

This commit is contained in:
pls.153 2022-11-24 10:09:31 +01:00
parent f9f4fe0221
commit bd0e71b8ec
3 changed files with 27 additions and 11 deletions

View file

@ -3,12 +3,11 @@
(in-package :s-http-server)
(defvar *web-server* nil)
(defconstant +buffer-length+ 8192)
(defvar *empty-line* #.(map 'vector 'char-code (list #\Return #\Linefeed
#\Return #\Linefeed)))
(defconstant +buffer-length+ 8192)
(defun form-data-filename (data start end)
"Searches for 'filename=' in current form data field header."
(let ((p1 (search #.(x:string-to-bytes "filename=\"")
@ -29,7 +28,7 @@
;; don't read past end, would block http connection
:for pos = (read-sequence buffer stream :end (min +buffer-length+
(- content-length index)))
do (adjust-array content (+ index pos))
:do (adjust-array content (+ index pos))
(replace content buffer :start1 index :end2 pos)
:while (< index content-length))
;; loop through all form-data and save file(s)
@ -105,12 +104,14 @@ it saves uploaded files on the server."
"Creates a *.zip file of passed directory, _not_ including the directory name."
(zip:zip (merge-pathnames zip-file)
(probe-file directory)
:if-exists :supersede))
:if-exists :supersede)
zip-file)
(defun unzip (zip-file &optional directory)
"Extracts (previously uploaded) *.zip file."
(zip:unzip (merge-pathnames zip-file)
(probe-file (or directory "."))
:if-exists :supersede))
:if-exists :supersede)
zip-file)
(export (list 'zip 'unzip))

View file

@ -98,7 +98,9 @@ port (mind the trailing `/`):
http://192.168.1.x:1701/
```
Now you can upload either a whole directory, or a single file. The files will
be stored in `[Home]/uploads/`.
be stored in `[Home]/uploads/`. Note that different browsers may behave
differently when uploading (recursive) directories (seems to work best with
either Firefox or Chromium based browsers).
You may also upload a zip file, which can then be unzipped using:
```

View file

@ -10,10 +10,10 @@
</style>
</head>
<body>
<h3>Upload files to CL REPL app</h3>
<h3>Upload files to REPL app</h3>
<form enctype="multipart/form-data" method="post" action="/">
<p>
<small><b>Whole Directory</b></small>
<small><b>Whole Directory</b> (recursive in Firefox/Chromium)</small>
<br>
<input name="files[]" type="file" webkitdirectory directory />
</p>
@ -26,6 +26,19 @@
<input type="submit" value="Upload" />
</p>
</form>
<small>Files are saved in <code>[Home]/uploads/</code></small>.
<small>
Files are saved in <code>[Home]/uploads/</code>.
<ul>
<li>uploaded zip files can be unzipped on the device with
<br><code>(unzip "all.zip" "examples/") ; android</code>
<br><code>(unzip "all.zip" "../Documents/examples/") ; iOS</code>
<br>&nbsp;
<li>files on the device can be zipped before downloading with
<br><code>(zip "all.zip" "examples/") ; android</code>
<br><code>(zip "all.zip" "../Documents/examples/") ; iOS</code>
<br>and downloaded like so:
<br><code>http://192.168.1.x:1701/all.zip</code>
</ul>
</small>
</body>
</html>