나는 tastypie에서 api를 만들고있는 모델을 가지고 있습니다. 수동으로 유지하는 파일의 경로를 저장하는 필드가 있습니다 (사용자가 파일을 업로드하지 않기 때문에 FileField
을 사용하지 않습니다). 파일 필드에 API의FileField in Tastypie
class FooModelResource(ModelResource):
file = fields.FileField()
class Meta:
queryset = FooModel.objects.all()
def dehydrate_file(self, bundle):
from django.core.files import File
path = bundle.obj.getAbsPath()
return File(open(path, 'rb'))
이 파일에 전체 경로를 반환
class FooModel(models.Model):
path = models.CharField(max_length=255, null=True)
...
def getAbsPath(self):
"""
returns the absolute path to a file stored at location self.path
"""
...
가 여기 내 tastypie의 설정입니다 : 여기에 모델의 요점이다. tastypie가 실제 파일이나 적어도 URL을 파일에 제공 할 수 있기를 바랍니다. 어떻게해야합니까? 모든 코드 스 니펫은 높이 평가됩니다.
감사합니다
'FileWrapper '는 어디에서 왔습니까? –
'django.core.servers.basehttp import FileWrapper' – astevanovic
파일 핸들이 클라이언트로 스트리밍 된 후 파일 핸들을 닫습니까? –