File Names Base64?

Discussion in 'A-Parser Support Forum' started by scrapefun, Apr 16, 2025 at 1:44 AM.

  1. scrapefun

    scrapefun A-Parser Enterprise License
    A-Parser Enterprise

    Joined:
    Feb 24, 2015
    Messages:
    191
    Likes Received:
    35
    I've been attempting to use:
    $tools.base64.encode(query);

    This saves files that appear to use base 64 for the files names but when I attempt to decode them I get output like:
    olv fw ׭8vrrku

    [%
    # Assign values based on regex matches
    image_group_value = p1.image.0.group == '' ? 0 : 1;
    image_result_value = p1.image1.0.result == '' ? 0 : 1;
    local_nav_value = p1.local.0.nav == '' ? 0 : 1;
    hotel_nav_value = p1.hotel.0.nav == '' ? 0 : 1;
    # Use Math module for directory calculation
    USE Math;

    # Encode the query to base64
    encoded_query = $tools.base64.encode(query);
    # Determine the output based on conditions
    IF image_group_value == 1 and local_nav_value == 0 and hotel_nav_value == 0 and image_result_value == 0;
    "empty_images/" _ encoded_query _ ".html";
    ELSE;
    "serp_raw/us-" _ Math.int(query.num / 900) _ "/" _ encoded_query;
    END;
    %]
     
  2. Support

    Support Administrator
    Staff Member A-Parser Enterprise

    Joined:
    Mar 16, 2012
    Messages:
    4,676
    Likes Received:
    2,198
    The case of characters in file names is not preserved, so you cannot decode the values correctly.
    For example, this template
    Code:
    [% tools.base64.encode('test') _ '.txt' %]
    will return the following string
    Code:
    dGVzdA==.txt
    But in the file name it might look like this:
    Code:
    dgvzda==.txt
     

Share This Page