Skip to content

Issue: Value cannot be null. (Parameter 'fileName')

Shelvin Datt edited this page Apr 5, 2025 · 1 revision

Issue: Azure Function 'UploadCsvToSftp' Failed - Missing SFTP Private Key Configuration

Date: 2025-04-05

Time (UTC): 21:26:22Z

Function: Functions.UploadCsvToSftp

Invocation ID: af67231e-51ef-43d2-ad1b-4b515856e61b

Reason: New blob detected (processed-csv/dispatch_19_SO123456.csv)

Error Message: 2025-04-05T21:26:22Z [Error] Error processing dispatch_19_SO123456.csv: Value cannot be null. (Parameter 'fileName')

Analysis:

The error message "Value cannot be null. (Parameter 'fileName')" within the context of an SFTP upload function strongly suggests that a required configuration setting related to the SFTP client is missing. Based on the description provided, the most likely cause is the absence of the environment variable that specifies the path to the private key used for SFTP authentication.

The function UploadCsvToSftp attempts to establish an SFTP connection to upload the processed CSV file. This often requires authentication using a private key. If the path to this private key is not correctly configured, the SFTP client initialization will fail, potentially leading to a null value being passed where the private key file path is expected.

Resolution:

To resolve this issue, you need to add and configure the following environment variable for your Azure Function App:

Environment Variable Name: SftpSettings:PrivateKeyPath

Environment Variable Value: The absolute or relative file path to the private key file located on the host where the Azure Function is running.

Steps to Configure the Environment Variable:

  1. Access your Azure Function App: Navigate to your Function App in the Azure portal.
  2. Go to Configuration: Under the "Settings" section in the left-hand menu, click on "Configuration".
  3. Navigate to Application settings: Ensure you are on the "Application settings" tab.
  4. Add a new application setting: Click on the "+ New application setting" button.
  5. Enter the Name: In the "Name" field, enter: SftpSettings:PrivateKeyPath
  6. Enter the Value: In the "Value" field, enter the full path to your private key file. For example:
    • If the key is stored directly on the function app's file system: /home/site/wwwroot/privatekey.pem (adjust the path based on your deployment)
    • If the key is managed through Azure Key Vault (in which case you'd typically use Key Vault references instead of a file path directly, but this error suggests a direct file path configuration is expected): The local path where the key might be temporarily accessed if that's your setup.
  7. Save the changes: Click the "Save" button at the top of the Configuration blade. This will likely trigger a restart of your Function App.

Important Considerations:

  • Security: Ensure that the private key file is stored securely and that the Function App has the necessary permissions to access it. Avoid hardcoding the private key directly as an environment variable value. Using a file path is generally a more secure approach when the file can be managed on the host. For production environments, consider using Azure Key Vault to manage sensitive information like private keys and using Key Vault references in your application settings.
  • File Path Accuracy: Double-check that the file path you provide is correct and that the private key file exists at that location on the Function App host.
  • Function Restart: After adding or modifying application settings, the Azure Function App will typically restart. Monitor the function logs after the restart to ensure the issue is resolved and the SFTP connection can be established successfully.

By adding and correctly setting the SftpSettings:PrivateKeyPath environment variable, the UploadCsvToSftp Azure Function should be able to locate and use the private key for SFTP authentication, resolving the "Value cannot be null" error.

Clone this wiki locally