2

Context

Using QGIS modeler (currently with QGIS 3.26.1) with the Download File algorithm, you can use a filename based on an expression and thus are able to give the saved file a name based on e.g. the current time, using the function now().

Question

The JSON-file I download this way contains an attribute named reference_ts with the timestamp of the measurement saved in it. I want to include this value in the filename. Is this possible?

What I tried

What is possible is to access this attribute in later steps after the saved file is loaded to QGIS, see here, because the layer loaded by a modeler algorithm can be accessed by a variable, created automatically, that gives access to the output of the algorithm. But in the Download File, there is not yet an output that could be accessed. So the attribute should be available directly.

enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208
  • I had the same problem. So I save the downloaded file in a temp folder (/var/tmp) because it needs to be downloaded to be used, it cant be a memory layer. I use an expression like this one '/var/tmp/'||'some_text_' || layer_property( @some_layer ,'name')||'_'||format_date(now(),'yyyyMMdd_HHmm')||'.csv'. Then I use the Load layer into project with the *"File destination" from algorithm "Download file"asUsing algorithm output` for the input layer. So the downloaded file should be usable in your model. – Charles Dec 05 '22 at 09:38
  • The problem is not how to include the current date/time (now()) in the filename - I solved that part. The question is rather how to include the value of an attribute in the filename. – Babel Dec 05 '22 at 09:41
  • 1
    OK maybe with two steps since the file can not be used before having been downloaded. – Charles Dec 05 '22 at 09:43
  • If you post this as an answer, I will accept it. – Babel Dec 05 '22 at 10:10

1 Answers1

2

Maybe you could do this with two steps since the file can not be used before having been downloaded : First download the and then load it to access the attributes.

I had the same problem. So I save the downloaded file in a temp folder (/var/tmp) because it needs to be downloaded to be used; it can't be a memory layer. I use an expression like this one:

'/var/tmp/'||'some_text_' || 
layer_property(  @some_layer ,'name')||'_'||
format_date(now(),'yyyyMMdd_HHmm')||'.csv'

Then I use the Load layer into project with the "File destination" from algorithm "Download file" as Using algorithm output for the input layer. So the downloaded file should be usable in your model.

Lilium
  • 1,057
  • 1
  • 6
  • 17
Charles
  • 360
  • 1
  • 14