Help with parser plugin

Hello,

We have a create financial institution parser plugin by manual upload file. When the import action in the function parseData(Context) but we got the temp file name (xx07xx93335xx6662xx.tmp) instead, Actually we need a real filename to upload.

Kindly suggest how to solve this problem.

Help with parser plugin

Rookie Asked on June 6, 2024 in SuiteCloud.

Hi,

Do you still need help with this?

Thanks,

Chris

on June 7, 2024.
Add Comment
2 Answer(s)
Best answer

The issue you’re facing is that the parseData function receives the temporary filename assigned during upload instead of the original filename. Here’s how to solve this and retrieve the actual filename:

Extracting from Context (if available):
Often, the context dictionary passed to parseData might contain additional information besides the temporary filename. Look for a key like “filename” or “original_filename” that might hold the actual filename. You can access it using context.get(“filename”).

Using File Attributes (Python specific):
If the context doesn’t provide the original filename, in Python, you can use the os.path.realpath function on the temporary filename. This resolves symbolic links and returns the actual path of the file, which might contain the original filename.

Here’s an example code snippet assuming the context contains the original filename:

import os

def parseData(context):
# Get the temporary filename (fallback to empty string if not available)
temp_filename = context.get(“filename”, “”)

# Check if original filename exists in context
actual_filename = context.get(“original_filename”)

# If not in context, try using os.path.realpath (assuming Python)
if not actual_filename:
actual_filename = os.path.realpath(temp_filename)

# Extract filename without path (optional)
# actual_filename = os.path.basename(actual_filename)

# Use the actual filename for further processing
# … your code to process the actual filename …

return actual_filename

This code first retrieves the filename from the context. If not available, it uses os.path.realpath to get the actual path (which might contain the original filename) on the assumption you’re using Python. Remember to adapt this code based on your specific programming language and context information availability.

Rookie Answered on June 7, 2024.
Add Comment

Hi,

Could you please explain why you need the actual file name inside parseData().

Thanks,

Chris

Advanced Answered on June 6, 2024.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor