im = storage.open('old_path_filename', 'r')
strorage.save('new_path_with_old_filename', im)
在我的django项目中,我将django-storages和Amazon S3用于我的静态文件和媒体文件。我需要将具有新路径的旧文件保存在亚马逊和旧文件名中。你可以帮帮我吗?
最佳答案
您可以使用Django的ContentFile
来执行此操作
from django.core.files.base import ContentFile
new_file = ContentFile(original_file.read())
new_file.name = original_file.name
example = Example()
example.file = new_file
example.save()
关于django - 如何使用django-storages和Amazon S3将文件从一个路径复制到另一路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16899049/