How to loop saving photo files

Hello, guys! :wave: I’m trying to loop a photo download. I was able to loop the parsing of files, but I can’t save them so that each file has its own name. When saving, the same name is simply overwritten.

BLOCK:HttpRequest
  url = "https://url.com"
  method = POST
  customHeaders = {("Action", "GetFiles"), ("x-requested-with", "XMLHttpRequest")}
  TYPE:STANDARD
  $"FileID=1%2F50&NextMarker=&flag=1&isRootImage=true&isFilesImages=true&InternalExternalMarker=true&selectedDevice=<deviceid>&selectedDeviceFlag=<deviceflag>"
  "application/x-www-form-urlencoded"
ENDBLOCK

BLOCK:Parse
LABEL:FileName
  input = @data.SOURCE
  leftDelim = "\"FileName\":\""
  rightDelim = "\""
  RECURSIVE
  MODE:LR
  => VAR @FileNames
ENDBLOCK

FOREACH FileName IN FileNames
// Query the single URL

BLOCK:Parse
LABEL:key
  input = @data.RAWSOURCE
  leftDelim = "ImageNew?Key="
  rightDelim = "\\"
  RECURSIVE
  MODE:LR
  => VAR @keys
ENDBLOCK

FOREACH key IN keys
// Query the single URL

BLOCK:HttpRequest
LABEL:url
  url = $"https://url.com/ImageNew?Key=<key>&Type=s&UserID=<UserID>&selectedDevice=<deviceid>"
  customHeaders = {}
  TYPE:STANDARD
  $""
  "application/x-www-form-urlencoded"
ENDBLOCK

BLOCK:FileWriteBytes
  path = $"D:\\x\\OpenBullet\\ob2\\url.com\\<input.USER>_<input.PASS>\\<FileName>.png"
  content = @data.RAWSOURCE
ENDBLOCK
END
END

I don’t really understand the keys part, does one “FileName” have multiple image links?

Yes. These are the names of the photos, there are as many of them as there are links to the photos.

So then to fix your issue could u do something like this:

BLOCK:FileWriteBytes
  path = $"url.com/<input.USER>_<input.PASS>/<FileName>_<key>.png"
  content = @data.RAWSOURCE
ENDBLOCK

filename_key so every file name is unique?

Thanks. This partially solved the problem. Now I get the following: img_1.png_key123.png, img_1png_key1234.png, img_1png_key1235.png.
But ideally I would like to: img_1.png, img_2.png, img_3.png. Because with the help of recursive parsing I got such values : img_1.png, img_2.png, img_3.png, But for some reason only the first value is taken - img_1.png :thinking: