hibou-io / hibou-odoo-suite

Hibou Suite: Hoot-Worthy Odoo Tools
GNU Affero General Public License v3.0
39 stars 63 forks source link

video uploaded cannot view online(file may be broken) #13

Closed JanusChoi closed 4 years ago

JanusChoi commented 4 years ago

I'm trying to develop a module to upload videos files via MinIO API of Python.

The file can be uploaded to MinIO, but it's cannot view via url like: http://localhost:9000/lms-videos/video/output.mp4. And also the file upload via MinIO should be 19.39Mb and the one uploaded via API turns out to be 25+MB, don't know what cause.....

Following is part of my code :

# minio client
@api.model
def _get_minio_client(self):
    host = '192.168.1.102:9000'
    access_key = 'minioadmin'
    secret_key = 'minioadmin'
    if not all((host, access_key, secret_key)):
        raise exceptions.UserError('Incorrect configuration of MinIO')
    return Minio(
    host,
    access_key = access_key,
    secret_key = secret_key,
    secure = False
    )
# upload
@api.model
def _store_file_write(self):
    client = self._get_minio_client()
    bin_data = self.datas_minio
    fname = "output_test"
    #client.put_object('lms-videos','videos/'+ fname + '.mp4',io.BytesIO(self.datas_minio), len(bin_data),'video/mp4')
    with io.BytesIO(self.datas_minio) as bin_data_io:
        client.put_object('lms-videos',
                          'videos/'+ fname + '.mp4',
                          bin_data_io,
                          len(bin_data),
                          'video/mp4')

@api.depends('document_id', 'slide_type', 'mime_type', 'external_url')
def _compute_embed_code(self):
    res = super(Slide, self)._compute_embed_code()
    for record in self:
        if record.slide_type == 'miniovideo':

            self._store_file_write()

            content_url = 'http://localhost:9000/lms-videos/videos/' + record.name + '.mp4'
            record.embed_code = '<video class="miniovideo" controls controlsList="nodownload"><source src="' + content_url + '" type=MPEG-4/></video>'

@api.onchange('datas_minio')
def _on_change_datas(self):
    res = super(Slide, self)._on_change_datas()
    if self.datas_minio:
        self._store_file_write()
len(bin_data),'video/mp4')
    return res
JanusChoi commented 4 years ago

Problem fixed by adding b64decode