我一直在使用Genie Framework和Stipple在Julia中开发一个应用程序,这个应用程序的主要任务是实现Sobel和Prewitt运算符。我正在努力解决的问题是上传程序组件。所以基本上我可以上传一个图像,点击按钮,图像就会被转换,但当我上传另一个图像并尝试输出它的转换版本时,我得到的输出仍然是旧图像。我一直在努力寻找这个问题,我注意到QUploader API有一些方法可以帮助解决这个问题:reset()
方法或removeUploadedFiles()
方法,但我不知道如何调用/使用这些关于Julia语法的函数。有可用的解决方案吗?
const FILE_PATH = "public/sample.jpg"
const FINAL_PATH = "final.jpg"
#const IMGPATH = "demo.png"
model = Model |> init
on(model.process_s3) do _
model.imageurl[] = ""
@info "Working"
img = FileIO.load(FILE_PATH)
img_gray = Gray.(img)
@info img_gray
sobel_image = convert(Array{Float64}, img_gray)
lastImage = clamp01nan.(sobel(sobel_image, sobel3_kernel_x, sobel3_kernel_y))
save(joinpath(@__DIR__, "public", FINAL_PATH), lastImage)
model.imageurl[] = "/$FINAL_PATH#$(Base.time())" * string(rand())
@info model.imageurl[]
if (model.process_s3[])
model.process_s3[] = false
end
end
function ui(model)
[
page( model,
class = "container",
title = "Card Demo",
partial = true,
[
row( # row takes a tuple of cells. Creates a `div` HTML element with a CSS class named `row`.
cell([h1("Edge Detection Project")]),
)
row(
[
cell(class="st-module", [
h2("Initial Image"),
card(
class = "q-pa-md row items-start q-gutter-md",
uploader(
label = "Upload Image",
method = "POST",
:multiple,
url = "http://localhost:8000/upload",
field__name = "img",
:finish="finished",
ref="uploader"
),
),
btn("Sobel 3x3",color="primary", @click("process_s3 = true")),
])
cell(class="st-module", [
h2("Transformed Image"),
card(
class = "q-pa-md row items-start q-gutter-md",
#quasar(:img, src=:imageurl, spinner__color="white", style="height: 300px; max-width: 350px")
imageview(src=:imageurl, spinner__color="white", style="height: 250px; max-width: 250px")
),
])
],
)
],
),
]
end
route("/") do
html(ui(model), context = @__MODULE__)
end
route("/upload", method = POST) do
if infilespayload(:img)
@info Requests.filename(filespayload(:img))
open(FILE_PATH, "w") do io
write(FILE_PATH, filespayload(:img).data)
@info File
end
else
@info "No image uploaded"
end
Genie.Renderer.redirect(:get)
end
# isrunning(:webserver) || up()
替换:
"/$FINAL_PATH#$(Base.time())"
带有
"/$(FINAL_PATH)?t=$(Base.time())"
说明:
#
只是一个指向HTML文档的锚链接。这显然会导致缓冲文档,因为浏览器可能只是在寻找不同的锚点(而找不到它们(,但没有重新下载的动机。
另一方面,添加?
使得每次请求实际上都不同(浏览器将其理解为不同的文档(。结果,缓存将不会被使用——请求一个新的副本。