Giter Club home page Giter Club logo

Comments (6)

etianen avatar etianen commented on August 30, 2024

from django-s3-storage.

saberworks avatar saberworks commented on August 30, 2024

Is there a way to get it if I'm not using the s3 storage as the default? I'm actually only using it for a handful of models that allow upload of user content. I have like storage=s3storage on individual file fields in the model. Thank you!

from django-s3-storage.

saberworks avatar saberworks commented on August 30, 2024

Answered my own question: the s3_connection is available from the specified s3storage connection as well:

            conn = s3storage.s3_connection

I'll add another comment with the working code and then close the ticket once I have it. Thank you!

from django-s3-storage.

saberworks avatar saberworks commented on August 30, 2024

It turns out the ETag is not a reliable source for a file hash. It changes not only depending on the content of the file, but also on how it was uploaded and what type of encryption was used. https://docs.aws.amazon.com/AmazonS3/latest/API/API_Object.html

I'm back to looking for a way to intercept the file before it's uploaded to s3. Does it ever reside on disk anywhere? In a temp directory or something?

Here's the working code I have to save the ETag, but it doesn't really solve the problem.

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)

        if(self.file):
            self.file_size = self.file.file.size

            conn = s3storage.s3_connection

            details = conn.head_object(
                Bucket=s3bucket,
                Key=str(self.file.file),
            )

            self.file_hash = details.get("ETag").replace('"', '')

            super().save()

from django-s3-storage.

etianen avatar etianen commented on August 30, 2024

from django-s3-storage.

etianen avatar etianen commented on August 30, 2024

from django-s3-storage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.