An open API service indexing awesome lists of open source software.

https://github.com/simonrolph/photo-to-api-app

Takes a picture, sends it to an API
https://github.com/simonrolph/photo-to-api-app

Last synced: about 1 month ago
JSON representation

Takes a picture, sends it to an API

Awesome Lists containing this project

README

        

# Photo --> API minimal web app

This is a lightweight web application that allows users to take a photo using their device's camera and upload the captured image to an API. Initial starting code was generated by ChatGPT

## Features

- Access the device's camera directly from the browser.
- Capture a still image from the live video stream.
- Preview the captured photo.
- Upload the photo to a specified API endpoint.

## Requirements

- A modern browser that supports `getUserMedia` (e.g., Chrome, Firefox, Edge, Safari).
- The device must have a camera.
- HTTPS is required for accessing the camera on most browsers.

## How to Use

1. **Open the App**: Load the `index.html` file in a browser.
2. **Grant Camera Permission**: Allow the browser to access your camera when prompted.
3. **Capture Photo**: Click the "Capture Photo" button to take a picture.
4. **Upload Photo**: Click the "Send Photo" button to upload the captured image to the API.
5. **View Status**: The status message will display whether the upload was successful or failed.

## File Structure

```
Camera-Capture-App/
|-- index.html # The main HTML file for the application.
```

## Customisation

### Changing the API Endpoint
To change the API where the image is uploaded, update the following line in the `index.html` file:
```javascript
const apiUrl = 'https://your-api-endpoint.com/upload';
```
Replace `'https://your-api-endpoint.com/upload'` with the URL of your API endpoint.

### Adjusting Image Format
The app captures images in PNG format by default. To change the format, modify this line:
```javascript
const photo = canvas.toDataURL('image/png');
```
Replace `'image/png'` with `'image/jpeg'` or any other supported format.

## Troubleshooting

- **Camera Not Accessible**: Ensure the browser has permission to access the camera. If using a laptop, ensure no other application is using the camera.
- **Upload Fails**: Verify the API endpoint is correct and supports receiving the image data.
- **HTTPS Requirement**: The app must be served over HTTPS (or localhost) for the camera to work on most browsers.

## Known Limitations

- The app does not store or cache the image locally.
- No advanced image editing or cropping features are provided.