簡體   English   中英

使用 django-audiofield、django-storages、boto 將音頻文件上傳到 s3。 django-storages 這個后端不支持絕對路徑錯誤

[英]Uploading a audio file to s3 with django-audiofield, django-storages, boto. django-storages This backend doesn't support absolute paths error

Django==1.8
django-audiofield==0.6.4
boto==2.38.0
django-storages==1.1.8

我目前在將音頻文件上傳到 S3 時遇到問題。 所有圖像都正確上傳。 當我嘗試上傳音頻時,我得到:異常類型:NotImplementedError 異常值:此后端不支持絕對路徑。 異常位置:.../lib/python2.7/site-packages/django/core/files/storage.py 在路徑中,第 115 行。

這是追溯的結束......

.../lib/python2.7/site-packages/audiofield/fields.py in _set_audio_converted
                    filename = self.generate_filename(instance, os.path.basename(getattr(instance, self.name).path)) ...


.../lib/python2.7/site-packages/django/db/models/fields/files.py in _get_path
                    return self.storage.path(self.name) ...


...c/lib/python2.7/site-packages/django/core/files/storage.py in path
                    raise NotImplementedError("This backend doesn't support absolute paths.") ...

我認為它也與

path(name)[source]¶ 可以使用 Python 的標准 open() 打開文件的本地文件系統路徑。 對於無法從本地文件系統訪問的存儲系統,這將引發 NotImplementedError。

來自https://docs.djangoproject.com/en/1.8/ref/files/storage/

我有它的工作......不完美,但它的工作原理。 我需要重寫 django-audiofield fields.py 的一部分。 特別是def _rename_audiodef _set_audio_converted因為它們都包含路徑方法,如果您不從本地提供靜態文件,則該方法不起作用。

就我而言,我收到此錯誤是因為我有一個額外的 Save 方法。

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')

    def __str__(self):
        return f'{self.user.username} Profile'

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

    #     img = Image.open(self.image.path)

    #     if img.height > 300 or img.width > 300:
    #         output_size = (300, 300)
    #         img.thumbnail(output_size)
    #         img.save(self.image.path)`

禁用圖像調整大小和保存方法后,錯誤消息消失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM