Generate image endpoints by posting base64 image data to a temporary URL.
rust-base64-resolver-gen is a Rust-based web service that allows users to upload base64-encoded images and retrieve them via unique URLs. This project is designed to facilitate the handling of image data in web applications, making it easy to generate temporary URLs for images.
- Accepts base64-encoded image data via a POST request.
- Generates a unique URL for each uploaded image.
- Allows retrieval of images using the generated URLs.
- Simple and efficient implementation using Actix-web.
- Rust (version 1.50 or later)
- Cargo (comes with Rust)
- Git (for cloning the repository)
- Clone the Repository
Open your terminal and run the following command to clone the repository:
git clone https://github.com/Tomato6966/rust-base64-resolver-gen.git- Navigate to the Project Directory
Change into the project directory:
cd rust-base64-resolver-gen- Build the Project
Use Cargo to build the project:
cargo build- Run the Server
Start the server with the following command:
cargo runThe server will start on http://127.0.0.1:8080.
To upload a base64-encoded image, send a POST request to the /image endpoint with a JSON body containing the base64 string. You can use tools like curl or Postman for testing.
Example using curl:
curl -X POST http://127.0.0.1:3555/image \
-H "Content-Type: application/json" \
-d '{"base64": "your_base64_encoded_image_here"}'Example Url Encoded:
curl -X POST http://127.0.0.1:3555/image \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "base64=your_base64_encoded_image_here"Response:
The server will respond with a URL to access the uploaded image:
{
"urlPath": "/image/{uuid}"
}To retrieve the uploaded image, send a GET request to the URL provided in the response.
Example:
curl -X GET http://127.0.0.1:8080/image/{uuid}Replace {uuid} with the actual UUID returned from the upload response.
Make sure your server is running by executing cargo run in the project directory.
- Convert your image to a base64 string. You can use online tools or libraries in various programming languages to do this.
- Use the
curlcommand provided above to upload your base64 string to the server.
After successfully uploading the image, you will receive a URL. Use this URL to access the image in your browser or through another HTTP client.
- Upload an Image:
curl -X POST http://127.0.0.1:8080/image \
-H "Content-Type: application/json" \
-d '{"base64": "iVBORw0KGgoAAAANSUhEUgAAAAUA..."}'Response:
{
"urlPath": "/image/4f430c6f-c2a5-4a66-84ca-12939dc6f172"
}- Retrieve the Image:
curl -X GET http://127.0.0.1:8080/image/4f430c6f-c2a5-4a66-84ca-12939dc6f172The image will be returned in the response. That means you can also just open it in the browser.
Contributions are welcome! If you have suggestions for improvements or new features, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Actix-web - The web framework used for this project.
- Base64 - The library used for encoding and decoding base64 data.
### Notes:
- Replace `"your_base64_encoded_image_here"` with an actual base64 string when testing.
- Ensure that the UUID in the example matches the format returned by your server.
- You can customize the README further based on your project's specific features or requirements.
You can visiualize the images easily with Postman with this POST-Request:
```js
function constructVisualizerPayload() {
var response = pm.response.json();
return { url: pm.variables.get("RUST_IMAGE_URL") + response.urlPath };
}
pm.visualizer.set(`<p><a href="{{url}}" target="_blank" style="color: white;">{{url}}</a></p><img src="{{url}}" alt="Generated Image" />`, constructVisualizerPayload());