# How to convert local image into base64 encoding

**URL:** <https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [December 6, 2023, 12:11pm UTC](https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372 "2023-12-06T12:11:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeripothula](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jeripothula](https://community.postman.com/u/jeripothula)\
**Post date:** [December 6, 2023, 12:11pm UTC](https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372/1 "2023-12-06T12:11:54Z")

</div>

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.’

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [December 6, 2023, 12:49pm UTC](https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372/2 "2023-12-06T12:49:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [December 6, 2023, 12:56pm UTC](https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372/3 "2023-12-06T12:56:38Z")

</div>

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.

> [@How to send a POST request with binary data as request body?](https://community.postman.com/t/how-to-send-a-post-request-with-binary-data-as-request-body/52776/3):
>
> Is that jpeg confidential? Are you ok with sending the jpeg to the Postman Echo service? If you send the request as form data, it will return the base64 encoding. For example… [image] [image] You can parse the response using something similar to the following to just return the base64 encoded string, let response = pm.response.json(); let base64 = response.files["dog.jpg"].split(",")[1]; console.log(base64) If you want to send this is a pre-request script then it will be similar but …

---

<div class="post-metadata">

**Author:** ![jeripothula](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jeripothula](https://community.postman.com/u/jeripothula)\
**Post date:** [December 6, 2023, 1:33pm UTC](https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372/4 "2023-12-06T13:33:59Z")

</div>

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

 ![postman_body](https://us1.discourse-cdn.com/getpostman/original/3X/0/7/0768da18b00aeeaaaed5bde7a46217a8b056b624.png)

 ![postman_prerq](https://us1.discourse-cdn.com/getpostman/original/3X/a/2/a2be1c4bc2ce4d65488322eb1c88f9ac73ebc36d.png)

---

<div class="post-metadata">

**Author:** ![jeripothula](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jeripothula](https://community.postman.com/u/jeripothula)\
**Post date:** [December 6, 2023, 1:35pm UTC](https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372/5 "2023-12-06T13:35:19Z")

</div>

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

 ![postman_body](https://us1.discourse-cdn.com/getpostman/original/3X/0/7/0768da18b00aeeaaaed5bde7a46217a8b056b624.png)

 ![postman_prerq](https://us1.discourse-cdn.com/getpostman/original/3X/a/2/a2be1c4bc2ce4d65488322eb1c88f9ac73ebc36d.png)

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [December 6, 2023, 2:30pm UTC](https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372/6 "2023-12-06T14:30:55Z")

</div>

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)](https://www.npmjs.com/package/newman#using-newman-as-a-library)

[[Feature] possibility to programatically write to a file · Issue #3033 · postmanlabs/postman-app-support · GitHub ](https://github.com/postmanlabs/postman-app-support/issues/3033)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [January 5, 2024, 2:31pm UTC](https://community.postman.com/t/how-to-convert-local-image-into-base64-encoding/55372/7 "2024-01-05T14:31:30Z")

</div>

Closed on January 5, 2024, 2:31pm UTC

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