我必须上传一个.zip文件并使用Django rest框架将其保存到服务器中的某个位置。我的代码是
`class upload_file(APIView):
parser_classes = (FileUploadParser,)
def post(self, request, filename, format=None):
file_obj = request.data['file']
destination = open('C:\\Temp\\' + filename, 'wb+')
for chunk in file_obj.chunks():
print(chunk)
destination.write(chunk)
destination.close()
return Response({"status":status.HTTP_204_NO_CONTENT, "data":file_obj})`
它创建一个带有filename
的.zip文件,其中包含另一个相同的.zip文件。提取内部zip包显示C:\Temp\files_backups\files_backups.zip: The archive is either in unknown format or damaged
消息
我试过这个时
`class upload_file(APIView):
parser_classes = (FileUploadParser,)
def post(self, request, filename, format=None):
file_obj = request.data['file']
with open('C:\\Temp', 'wb+') as temp_file:
for chunk in file_obj.chunks():
temp_file.write(chunk)
return Response({"status":status.HTTP_204_NO_CONTENT, "data":file_obj})`
显示exceptions.IOError: [Errno 13] Permission denied: 'C:\\Temp'
我经历了很多解决方案,但没有找到任何合适的解决方案。任何人都可以指导如何上传.zip文件并将其保存到C:\Temp
文件夹?
提前致谢。