如何将zipfile.ZipExtFile转换为pygltflib.GLTF2.load参数的可接受类型?

问题描述

我有一个带有ViewSet方法的Django post类。使用上述视图类,我注册了一个API端点。发送POST请求时,API终结点接受主体的表单数据中的zip文件。
该zip文件中包含几个GLB文件。每个GLB文件可能具有一对多的网格。我需要从每个GLB文件中获取所有网格名称。
要加载GLB文件,我想使用glb_file = GLTF2().load(filename)。要获得所有我认为可以做的meshes = glb_file.meshes网格物体。
这是我的views.py的一部分:

from rest_framework.viewsets import ViewSet
from rest_framework.response import Response
from rest_framework import permissions
from django.core.files.base import ContentFile
from zipfile import ZipFile
from pathlib import Path
from pygltflib import GLTF2
from .models import *


class AssetCreateZipView(ViewSet):
    permission_classes = [permissions.IsAuthenticated]

    def list(self,request):
        return Response('Make post request by uploading a zip file containing asset files.')

    def post(self,request):
        # form-data key = zip.
        request_data = request.FILES['zip']

        with ZipFile(request_data,'r') as zip_obj:
            zip_name = Path(zip_obj.filename).stem

            # traverse through assets.
            for name in zip_obj.namelist():
                with zip_obj.open(name,'r') as file:
                    product = Product.objects.get(name__iexact=zip_name)

                    glb_file = GLTF2().load(file)  # the error occurred here.
                    meshes = glb_file.meshes
                    # for mesh in meshes,Mesh.objects.create(product=product,name=mesh)

*** TypeError:预期的str,字节或os.PathLike对象,而不是ZipExtFile

哪种数据类型(str / bytes / os.PathLike对象)更适合我的情况?以及如何做?

我使用的参考文献:
https://pypi.org/project/pygltflib/
https://docs.python.org/3/library/zipfile.html

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...