This API generates QR codes for provided URLs and uploads the generated PNG image to Azure Blob Storage. The API is built with FastAPI.
- Generates a QR code image from a URL.
- Uploads the generated image to Azure Blob Storage.
- Returns the public URL for the uploaded QR code image.
- Python 3.8 or newer
- FastAPI
- Uvicorn
- Azure Storage Blob
- python-dotenv
- Environment variables configured (see below)
-
Clone the repository and navigate into the API directory:
git clone <repository-url> cd \qr-code-generator\api
-
Install Dependencies:
Create a virtual environment and install the required packages:
python -m venv .venv source .venv/bin/activate # On Linux/Mac .venv\Scripts\activate # On Windows pip install -r requirements.txt
-
Configure Environment Variables:
Create a
.envfile in the same directory asmain.pyand add:AZURE_STORAGE_CONNECTION_STRING=<your-azure-storage-connection-string> AZURE_CONTAINER_NAME=<your-container-name> # e.g., "qr-codes" AZURE_STORAGE_ACCOUNT=<your-storage-account-name>
These variables are used to connect to your Azure Blob Storage instance.
Start the API with Uvicorn:
uvicorn main:app --reloadThe API will be available at http://localhost:8000.
- Description: Generates a QR code for the provided URL and uploads the image to Azure Blob Storage.
- Request Body:
A form or query parameterurlwith the URL you wish to generate a QR code for. - Response:
JSON object containing the QR code image URL:{ "qr_code_url": "https://<storage-account>.blob.core.windows.net/<container>/<file-name>.png" }
-
QR Code Generation:
The API creates a QR code using the qrcode library with specified parameters such as version, error correction, box size, and border. -
Image Storage:
The generated image is saved into aBytesIOobject in PNG format. -
File Naming and Upload:
A file name is generated based on the provided URL. The file is then uploaded to Azure Blob Storage using the specified container.
The file name format is:qr_codes/<url-domain>.pngNote: The code uses a folder named
qr_codesinside your Azure container. -
Response:
A URL that points to the uploaded blob is constructed and returned in the API response.
-
Azure Blob Upload Issues:
Check that your Azure Storage connection string and container name are correct. Ensure that the container allows public blob access for retrieving the QR code image. -
Environment Variables:
Verify that your.envfile is properly configured and that environment variables are being loaded (usingpython-dotenv). -
Logging:
The API prints errors to the console if issues occur during the upload process.
This project is licensed under the MIT License. (Update as needed.)