https://prefect.io logo
g

Giacomo Chiarella

07/28/2023, 1:44 PM
is it possible to upload a file in a deployment parameter?
n

Nate

07/28/2023, 2:22 PM
@Giacomo Chiarella all flow run parameters must be JSON serializable, so not quite. what's common is to pass a reference (
str
or
Path
) to the flow run so that it can load it from wherever it is
g

Giacomo Chiarella

07/28/2023, 2:25 PM
@Nate using a Path parameter would allow me to upload the file from my local pc and use the content in the flow? Do you have an example please?
n

Nate

07/28/2023, 2:33 PM
you'd need to be able to read from the file from within the flow, but this is one reason why we have storage blocks
Copy code
In [10]: from prefect import flow

In [11]: from prefect.filesystems import GCS

In [12]: @flow(log_prints=True)
    ...: def read_and_use_file(path: str):
    ...:     bucket = GCS.load("marvin-code-storage")
    ...:     return bucket.read_path(path)
    ...:

In [13]: read_and_use_file("projects/test.py").decode("utf-8")
Out[13]: 'from prefect import flow\n\n@flow(log_prints=True)\ndef hello_world():\n    print("Hello, world!")'
g

Giacomo Chiarella

07/28/2023, 2:34 PM
that is not what I’m looking for, I’m looking for something which is more like an upload button
without storing anything anywhere
n

Nate

07/28/2023, 2:36 PM
hmm, like from the UI you'd want to drag and drop a file into a parameter field for a flow run? I'm pretty sure that's not possible at this time
g

Giacomo Chiarella

07/28/2023, 2:37 PM
exactly. I would not use a block to save temporary configuration files as the user would need to remember to delete the block otherwise you end up in a lot of junk blocks
and a lot of confusion
n

Nate

07/28/2023, 2:40 PM
you can programmatically create and delete blocks pretty easily with
save
and
delete
so they could always live for the duration of the flow run anyways, while uploading files like that is not supported, let me know if there's something else I can help with
thank you 1