I'm building a django application that will be operated via desktop application. Key feature for now is sending/storing files. Basically I need a django view with URL on which I can send files with POST and this view will store the files. Currently I have something like this :
def upload(request):
for key, file in request.FILES.items():
path = settings.MEDIA_URL + '/upload/' + file.name
dest = open(path.encode('utf-8'), 'wb+')
if file.multiple_chunks:
for c in file.chunks():
dest.write(c)
else:
dest.write(file.read())
dest.close()
destination = path + 'files_sent.txt'
file = open(destination, "a")
file.write("got files \n")
file.close
and urlconf:
url(r'^upload/$', upload, ),
that supports sending chunked files. But this doesn't work. Is the code correct ? Should I take a different approach, like providing a model with file field and in this function creating a new model instance instead of writing file to disk ?