In a view, I am generating a file, saving it as a field in a Django model (an file field) and returning the url:
...
obj.pdf.save(obj.hash_id + '.pdf', File(open(destination_path, 'r')))
ret = {
'pdfUrl': obj.pdf.url
}
ret = json.dumps(ret)
return HttpResponse(ret, mimetype='text/plain')
The user is then redirected to the url that is returned in ret, which sometimes is a blank pdf, but if they refresh a second later, the full pdf is there. I suspect S3 is not finished saving it down on their end. Is there any clean way in Django to make sure the file is accessible before returning the url?