1

I am using django-storages with boto. Everything works fine if I let storages handle S3 file uploads in my model as public. However when I set the ACL to private on save/update I get this error message

S3ResponseError: 404 Not Found
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>https:/s3.amazonaws.com/mahbuckit/mods/1366814943/1363379259-re6pc-x-l4d2-the-witch-psd-jpgcopy.zip</Key><RequestId>9631D1222C18F323</RequestId><HostId>bmMgn75bqITigKJWM7L7JrjN2TcsPCslOt9d3LX6WvzxWbHcdBfeqBIdFSZsmhXW</HostId></Error>

This happens on Add/update of record.

This is my save part for the Model where I have FileFIeld. I override to set the acl to private.

 def save(self, *args, **kwargs):
        super(MyModel, self).save(*args, **kwargs)
        if self.file:
            conn = boto.connect_s3(settings.AWS_ACCESS_KEY_ID,settings.AWS_SECRET_ACCESS_KEY)
            bucket = conn.create_bucket(settings.AWS_STORAGE_BUCKET_NAME)
            k = boto.s3.key.Key(bucket)
            k.key = settings.MEDIA_URL + self.file.name
            k.set_acl('private')

However the file saves all ok. It's the damn errors.

Taylan Aydinli
  • 4,333
  • 15
  • 39
  • 33
Abhishek Dujari
  • 2,343
  • 33
  • 43

2 Answers2

1

I found the problem. In reference to the good person whose work I used and modified http://www.gyford.com/phil/writing/2012/09/26/django-s3-temporary.php

I noticed that I construct the Key with URL. authors points out in twitter. Which is the whole reason for the error message. Lack of sleep but the error message clearly says missing Key but shows a URL instead of a key. That my problem right there. Key should be a file or path+file name.

Abhishek Dujari
  • 2,343
  • 33
  • 43
  • I must say I still get 404 on form post on production but not locally after my fix mentioned above. I think I may have missed something or a new problem has cropped up. – Abhishek Dujari Apr 25 '13 at 17:10
  • The post you cite looks quite useful, but is quite out of date. Any references to do the same that are more up to date? – Dylan May 19 '21 at 18:47
0

It looks like from what I've tested, you need the k.key to reflect self.file.name:

k.key = self.file.name
Brittney
  • 1
  • 1