How to convert local image into base64 encoding

I am using API to create test execution with evidence attaching as well.
So, used prerequiste tab to generate base64 encoded which used in data in evidence tag.
I am facing issues in prerequiste script. unable to upload attachment
and even evidence attached getting error ‘The requested content cannot be loaded.
Please try again later.’

Hey @jeripothula,

Welcome to the Postman community! :postman:

Can you provide more details about the request you’re making, the code you have used in the pre request script and some screenshots of the app which shows the issue please?

You haven’t detailed what you’ve tried, or included details on what code you currently have.

You will not have access to the local file system within the pre-request script.

If the API requires an base64 encoded string, you will either need to decode this before hand using another tool, or you could potentially send a request to Postman Echo as form data including the file, and the response returned will include the base64 encoding which you can then parse and use in your subsequent request.

Have a look at the following post to see how to use Postman Echo to return the base64 encoded string for a file.

Hi Danny,

I want to create Test execution in jira with evidence included. I have converted image into base64 encoded online and used that generated code in data, it worked . Now I decided to write script in prerequisite to generate base64encoded for local stored image. But it not worked.

Please check below screenshot

Hi Mike,

I want to create Test execution in jira with evidence included. I have converted image into base64 encoded online and used that generated code in data, it worked . Now I decided to write script in prerequisite to generate base64encoded for local stored image. But it not worked.

Please check below screenshot

You cannot access the local file storage in the pre-request script.

It’s not supported in the Sandbox.

Your URL for the sendRequest is not an API that will return data. GET and POST are HTTP methods. The FILE method is not part of the HTTP standard. It’s just something that browsers have included over the years.

You are limited to getting the base64 encoded string somewhere else, or using another API to do the base64 encoding. (Hence the option of using Postman Echo which I appreciate may or may not be possible due to security concerns, etc).

The other option is to use Newman and node.js (so you can include the fs library).

Here are some links and examples if you have to go that route.

newman - npm (npmjs.com)

[Feature] possibility to programatically write to a file · Issue #3033 · postmanlabs/postman-app-support · GitHub

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.