3👍
✅
The Cloud Run HTTP request/response size is limited to 32Mb. Use a multipart/form-data
to send chunks of your big file and not the whole file directly.
2👍
Thank you @guillaume blaquiere! I solved download error. I post my code for othres.
def _file_iterator(file, chunk_size=512):
with open(file, 'rb') as f:
while True:
c = f.read(chunk_size)
if c:
yield c
else:
break
def download_view(request,pk):
file_path = f'media/{pk}.mp3'
file_name = f'{pk}.mp3'
response = StreamingHttpResponse(_file_iterator(file_path))
response['Content-Type'] = 'audio/mpeg'
response['Content-Disposition'] = f'attachment;filename="{file_name}"'
return response
I think StreamingHttpResponse is key point of this problem. It’s return big file by chunks. It dose not over Cloud Run’s limit.
When I used multipart/form-data
for Content-Type, I could download file. But it’s couldn’t open on smart phone, because It couldn’t select application. When I download on PC, it’s can’t show audio file icon. We should select exact content type.
👤Nori
- [Django]-Radical Use of Admin's Interface
- [Django]-ImportError : no module named 'models'
- [Django]-User.groups.add(group) or group.user_set.add(user), Which is better and why ? or difference between them
Source:stackexchange.com