horilla icon indicating copy to clipboard operation
horilla copied to clipboard

S3 as media path - Not able to view

Open TheSuperAgent opened this issue 1 year ago • 1 comments
trafficstars

I use S3 as the storage, I have uploaded documents in the employee section, but when I click on view, Im not able to view it. image

TheSuperAgent avatar May 28 '24 14:05 TheSuperAgent

Hi @BhuviTheDataGuy , Can you please confirm in the s3 bucket whether the document is uploaded in the bucket?

With Regards, Team Horilla

horilla-opensource avatar May 30 '24 05:05 horilla-opensource

Hi @BhuviTheDataGuy , We are closing this issue due to inactivity. It seems that there hasn't been any recent activity or discussion, and we believe it may have been resolved or is no longer relevant. If you feel this issue is still important and should be addressed, please feel free to reopen it or create a new issue with updated details.

With Regards, Team Horilla

horilla-opensource avatar Nov 01 '24 10:11 horilla-opensource

For anyone coming here from the blog The code in the blog does not work at this point (at least as of version 1.2.1). The reason is that when using S3Boto3Storage, the horilla code invokes document.path here, and document is stored at s3 so it can't find it and raises an error of "This backend doesn't support absolute paths" There is a quick and dirty fix to make this work:

import tempfile
import os
from storages.backends.s3boto3 import S3Boto3Storage

class PrivateMediaStorage(S3Boto3Storage):
    """
    PrivateMediaStorage
    """

    default_acl = "private"
    file_overwrite = False

    def path(self, name):
        temp_dir = tempfile.mkdtemp()
        fn = name.split("/")[-1]
        temp_file_path = os.path.join(temp_dir, fn)
        file = self._open(name, mode='rb')
        with open(temp_file_path, 'wb') as temp_file:
            temp_file.writelines(file)

        return temp_file_path

Maybe the @horilla-opensource team can make a more "permanent" fix for it here?

phantom943 avatar Dec 11 '24 15:12 phantom943