How use FileField model with ReportBro with Django?

I have a FileField field in a Django model that I want to read to display in my ReportBro report that use AWS S3 Bucket.

class Inspection_File(models.Model):
inspection = models.ForeignKey(Inspection, null=True, on_delete=models.CASCADE,
                               related_name='fk_inspection_inspectionfile')
imageNumber = models.IntegerField(null=True, blank=True)
file_name = models.CharField(max_length=500, null=True, blank=True)
file = models.FileField(max_length=500, storage=InspectionDataStorage(), null=True, blank=True)
thumbnail = models.CharField(max_length=500, null=True, blank=True)
category = models.ForeignKey(Inspection_File_Category, null=True, on_delete=models.CASCADE,
                             related_name='fk_inspfilecategory_inspectionfile')
commentary = models.TextField(blank=True, null=True)

class Meta:
    db_table = 'ins\".\"file'

ReportBro has 3 ways to print images, open a local file, by base64, or by URL images_reportbro. However, in my case, using the URL is a very long process, so I need to read the file to keep it in memory and send it directly to the report. Try using this code:

test = image.file.open(mode='rb')

It has not worked, the report does not give me an error but the spaces appear blank, as if it did not recognize the type of file that I am sending. But when I open a file from my directory it works. When reviewing the data types I realized that locally I have an io.BufferedReader and in the other a FileField Class.

marker_image = open('media/db model.png', 'rb')
# <class '_io.BufferedReader'>
test = image.file.open(mode='rb')
# <class 'django.db.models.fields.files.FieldFile'>

In theory, that would be the main problem why it doesn’t work, does anyone know if a FileField can be transformed into a BufferedReader?

See the docs for FieldFile.

Basically, the issue is that you’re limited to what the Storage class provides as an API for opening and reading files. So it’s less a “Django” issue and more one of whatever S3 interface you’re using (and the capabilities of the AWS S3 API).