1

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?

zallarak
  • 5,287
  • 7
  • 38
  • 54

2 Answers2

0

Access the object yourself, in the script, by the means the user would, and see if its size meets a certain threshold, or if you know the size, if it is all there.

Skaperen
  • 453
  • 4
  • 13
0

According to several people in the boto IRC channel, because S3 is distributed, there is no way to tell if the file you've uploaded has propagated. But it will happen pretty quickly. Hope this helps anyone else with this issue; you just have to wait a bit. This may change in the future though.

zallarak
  • 5,287
  • 7
  • 38
  • 54