Local S3 Connection to Default Uploader
In this guide, we will locally set up MinIO, connect it to Default Uploader, and transform a file. Let’s go!
1. Create a docker-compose file
This script will download the MinIO image and a utility that will create a user, access keys, and a bucket.
version: '3.8'
services: minio: image: minio/minio:latest container_name: minio environment: - MINIO_ROOT_USER=admin - MINIO_ROOT_PASSWORD=admin123 ports: - "9000:9000" - "9001:9001" volumes: - minio_data:/data command: server /data --console-address ':9001'
minio_mc: image: minio/mc:latest container_name: minio_mc depends_on: - minio volumes: - ./wait-for-it.sh:/wait-for-it.sh entrypoint: > sh -c " chmod +x /wait-for-it.sh && /wait-for-it.sh minio:9000 --timeout=30 --strict && mc alias set myminio http://minio:9000 admin admin123 && if mc admin user info myminio my_access_key >/dev/null 2>&1; then echo 'User my_access_key already exists, skipping user creation'; else mc admin user add myminio my_access_key super_secret_key; fi && if mc ls myminio/mybucket >/dev/null 2>&1; then echo 'Bucket mybucket already exists, skipping bucket creation'; else mc mb myminio/mybucket; fi && if mc admin policy info myminio readwrite --user=my_access_key >/dev/null 2>&1; then echo 'Policy readwrite already attached to user my_access_key, skipping policy attachment'; else mc admin policy attach myminio readwrite --user=my_access_key; fi && echo ' The first two keys are needed to log into the MinIO WebUI management console, the second two keys are Access Key ID and Secret Access Key in your personal account admin.defaultuploader.com' && echo 'Username Minio UI: admin' && echo 'Password Minio UI: admin123' && echo 'Access Key: my_access_key' && echo 'Secret Access Key: super_secret_key' "
volumes: minio_data:
2. Create wait-for-it.sh
Copy the file from this GitHub repository.
Your file structure should look like this:
Directoryminio-for-local-development/
- …
- docker-compose.minio.yml
- wait-for-it.sh
3. Run the script
cd minio-for-local-development &&docker-compose -f docker-compose.minio.yml up
MinIO will be installed, and a user, bucket, and access keys will be created.
// The console output will look like this; you'll need these details in step 5...minio_mc | Username Minio UI: adminminio_mc | Password Minio UI: admin123minio_mc | Access Key: my_access_keyminio_mc | Secret Access Key: super_secret_key
4. Open MinIO to the internet
You can use any tool for this; the example will use ngrok. You need to expose the MinIO API port to the internet.
ngrok http 9000
Copy the address from the Forwarding field:
// Example:...Forwarding https://332e-185-103-25-11.ngrok-free.app -> http://localhost:9000
5. Enter the S3 connection details obtained in the previous steps
S3 connection settings in the Default Uploader dashboard:
Access Key ID -> my_access_keySecret Access Key -> super_secret_keyRegion -> us-east-1Bucket -> mybucketFile endpoint -> {URL} from step 4
Click the Save button and then Check Connection. Also, enable the Soft Migration option, which will be useful in the next step.
6. Verification
Go to the MinIO console.
Enter the login details:
Username -> adminPassword -> admin123
Go to the bucket bucket and upload any image.
Directorymybucket/
- cat.jpg
Now, generate a link to retrieve and optimize the file.
https://api.defaultuploader.com/v1/image/upload/CLIENT_TOKEN/S3_FILE_PATH
CLIENT_TOKEN can be found in your dashboard.
You should end up with a link containing your CLIENT_TOKEN and the name of the uploaded file.
https://api.defaultuploader.com/v1/image/upload/66c78a393438de9506dd5e09/cat.jpg
And add the parameter ?w=100
https://api.defaultuploader.com/v1/image/upload/66c78a393438de9506dd5e09/cat.jpg?w=100
Done! You have successfully connected a local S3 to Default Uploader.