https://github.com/chifisource/toolipsuploader.jl
A toolips file-uploader with server-side saving.
https://github.com/chifisource/toolipsuploader.jl
Last synced: 4 months ago
JSON representation
A toolips file-uploader with server-side saving.
- Host: GitHub
- URL: https://github.com/chifisource/toolipsuploader.jl
- Owner: ChifiSource
- License: mit
- Created: 2022-06-27T17:36:54.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-08-18T00:16:45.000Z (10 months ago)
- Last Synced: 2025-11-28T13:29:21.952Z (7 months ago)
- Language: Julia
- Homepage:
- Size: 89.8 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
- [documentation](https://chifidocs.com/Toolips/ToolipsUploader)
- [Toolips](https://github.com/ChifiSource/Toolips.jl)
#### uploader
`ToolipsUploader` demistifies the process of uploading files from the client to the server using a simple `ToolipsSession` extension alongside the `UploadMap`. This is more of an extension to `ToolipsSession` than it is base `Toolips`, and **requires the `Session` extension** to be loaded into your server.
```julia
using Pkg
Pkg.add("ToolipsUploader")
# Latest breaking changes, sometimes broken or version mismatched
Pkg.add("ToolipsUploader", rev = "Unstable")
```
###### explanation
Uploading is handled via three functions bound to the `UploadMap` using `bind`. These are `:init`, `:progress`, and `:complete`.
```julia
upm = ToolipsUploader.UploadMap()
bind(upm, :complete) do cm::ComponentModifier
open(upl_path, "w") do o::IOStream
write(o, upl_data)
end
@info "wrote file"
push!(cm.changes, "console.log('file written');")
end
```
This is a minimal example, the following example is a full server and includes all features:
```julia
module ToolipsUploadExample
using Toolips
using Toolips.Components
using ToolipsUploader
using ToolipsSession
main = route("/") do c::Connection
loader = ToolipsUploader.fileinput("sampy")
upm = ToolipsUploader.UploadMap()
upl_path = ""
upl_data = ""
# init function
function upm_init(cm::ComponentModifier, num::Int64, value::AbstractString)
if ~(isfile(value))
touch(value)
end
upl_path = value
@info "file upload $value started"
push!(cm.changes, "console.log('file upload started');")
end
# progress function
function upmprog(cm::ComponentModifier, info::StreamFileInfo)
upl_data = upl_data * info.data
push!(cm.changes, "console.log('uploaded $(info.loaded) of $(info.size)');")
end
# complete function
bind(upm, :complete) do cm::ComponentModifier
open(upl_path, "w") do o::IOStream
write(o, upl_data)
end
@info "wrote file"
push!(cm.changes, "console.log('file written');")
end
# bind to other loader:
bind(upm_init, upm, :init)
bind(upm_init, upm, :upmprog)
new_button = button("trhh", text = "UPLOAD")
Components.bind(new_button, loader)
Components.bind(c, loader, upm)
write!(c, h2(text = "welcome to me uploader"))
write!(c, loader, new_button)
end
SES = Session()
export SES, main, default_404
end # module
```