问题描述
我有一个带有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 (将#修改为@)