reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
17.95k stars 994 forks source link

`get_upload_url` does not work as expected #3602

Open bin-san opened 4 days ago

bin-san commented 4 days ago
class ImageOperationState(r.State):
    source_image:str = '/sample.jpg'

class SomeState(r.State):
    imgopst = await self.get_state(ImageOperationState)
    imgopst.source_image = r.get_upload_url(outfile) # this would not work

printing the source_image gives:

{"state": "", "interpolations": [[0, 28]], "imports": {"/utils/state": [{"tag": "getBackendURL", "is_default": false, "alias": null, "install": true, "render": true, "transpile": false}], "/env.json": [{"tag": "env", "is_default": true, "alias": null, "install": true, "render": true, "transpile": false}]}, "hooks": {}, "string_length": 114}{`${getBackendURL(env.UPLOAD)}/uploaded_files/test2.png-1a6d83df-f67a-4ff6-bc13-ae2214abab93-1719775789482107314`}

Instead of the image path

masenf commented 4 days ago

is it feasible to move the rx.get_upload_url bit to the frontend code and only store outfile in the ImageOperationState?

get_upload_url is intended for frontend rendering, but it does sort of work on the backend for the limited case of being passed to rx.download