last day (15 days later) » 

1:53 PM
0
A: Copy a File from one Model's FileField to another Model's FileField without reading it

GasanovYes, you have to create new file instead of just copy the path of old file. For example: from django.core.files.base import ContentFile new_file = ContentFile(test_object.some_file.read()) new_file.name = os.path.basename(test_object.some_file.name) transfer_object.transferred_file = new_file t...

 
yeah, that's something I already know. But, is there a way where I don't have to read the file cause the file is huge and I don't want it in my memory.
 
You didn't said that file is big or you don't want it in memory.
 
I made the edit, thanks
 
@yadavankit not exactly sure it will work with s3, but that is working fine on local server.
 
yeah .path won't work on s3
 
1:53 PM
are you using django-storages?
 
django defaul-storage yes
 
defaul-storage?
 
default-storage
if that's what you're asking
 
I mean do you use app called django-storages to access S3?
that's popular app to do that kind of stuff
 
from storages.backends.s3boto import S3BotoStorage
i use this for s3
 
okay cool
so, what do you suggest?
.path is actually not working here on s3
 
just use boto that comes with that app
to upload file on s3 bucket
 
okay, just a sec
 
2:12 PM
well, I can check it myself, but in 1.5 hour, since I'm not on my pc right now
 
yeah i used boto
but .path is not available on boto
 
yeah, path is not, so you need to use lowlevel functions that are defined in file I linked
 
2:42 PM
ohh okay, let me try
 
 
2 hours later…
4:21 PM
I updated answer for S3. It is assuming both files are in same bucket
(which is probably correct for everyone, since you can configure only 1 bucket name but anyway)
and technically might not work everytime, since you require accessing by key property and not by name, but usually they are the same
 
4:32 PM
nvm, made access by key
not sure if that is really better, but i guess key is not always equal name, so yeah
 

last day (15 days later) »