As often happens to me, things are much less complicated than i figure out
I loose hours running after UploadedFile, HttpRequest, etc.
Finally, it was my fault, a wrong path
Using os.path.join(settings.MEDIA_ROOT, 'images') create a new tree from
static folder
Using os.path.join(settings.MEDIA_URL, 'images') return '/static/images'
that gives error (path does not exist) while using 'static/images' it
works now
(it's a test command, in real example i will load name from a file
passed by args)
------------------------------------------------------------------------------------------------------------------------------
from django.core.management.base import BaseCommand, CommandError
import os
ffiles = []
ffiles.append('/mnt/hostdir/project/fotoalkatron/SNC110.jpg')
ffiles.append('/mnt/hostdir/project/fotoalkatron/SNC111.jpg')
ffiles.append('/mnt/hostdir/project/fotoalkatron/SNC112.jpg')
class Command(BaseCommand):
def handle(self, *args, **options):
_upload_img()
def _upload_img(fname):
for fpathname in ffiles:
fname = os.path.split(fpathname)[1]
_dst= os.path.join( 'static/images', fname)
myfl = open(fpathname,'r')
cntn = myfl.read()
myfl.close()
fdst = open(_dst,'wb')
fdst.write(cntn)
fdst.close()
-------------------------------------------------------------------------------------------------------------------------------