4

我一直在使用 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()

4

1 回答 1

2

代替:

"/$FINAL_PATH#$(Base.time())"

"/$(FINAL_PATH)?t=$(Base.time())"

解释:

#只是一个指向 HTML 文档的锚链接。这显然会导致文档缓冲,因为浏览器可能只是寻找不同的锚点(而不是找到它们)但没有重新下载的动机。

另一方面,添加?使请求实际上每次都不同(浏览器将其理解为不同的文档)。结果将不使用缓存 - 请求新副本。

于 2022-01-13T01:22:01.267 回答