Saving photo to blob column
Describe the issue
Qgis can store image as blob. However, I found no qgis functions which can easily link an "attachement" type of the attribute form to the blob field. My aim is to store the photos taken in QField in the blob column. As Qfield as no python support, I didn't find a way to do it.
Reproduction steps
Steps to reproduce the behavior:
- Create a table with a column "photo_path" to store the image filepath and take pictures in Qfield
- Create a column "photo" with a binary column
- Use a function in the default value field of "photo" to convert the photo to a binary object
Qgis function to_base64( "photo_path" ) doesn't do the job so I did a python function :
from qgis.core import *
from qgis.gui import *
@qgsfunction(args='auto', group='Custom')
def bloby(image_path):
import base64
with open(image_path, "rb") as image_file:
img_blob = base64.b64encode(image_file.read())
return img_blob.decode('utf-8')
This function does the conversion in Qgis : from_base64( bloby( "photo_path" ))
Expected behavior
blob field stays empty in Qfield, not in Qgis
Desktop (please complete the following information)
- OS: Windows 10
- QGIS 3.32.1
- QFieldSync Version 4.6.0
Mobile (please complete the following information)
- Device: MI 12
- OS: Android 10
- QField version: 2.8.7
Additional information
- Problem started happening recently, didn't happen in an older version of QField: don't know
- Problem can be reliably reproduced, doesn't happen randomly: Yes
- Problem happens with all files and projects, not only some files or projects: Yes
Part of the issue is in QGIS itself which doesn't allow setting an 'Attachment' widget on a BLOB column. However, QGIS does allow the user to 'embed' a file but this doesn't appear as an option in Qfield, so there is no way to attach a photo or file to a blob column in QField.