I need to process an uploaded file with GeoDjango. According to the documentation, I should use Datasource()
constructor from GDAL.
Problem is that size of uploaded shapefiles can be less than 2.5 MB, so MemoryFileUploadHandler
is used by default and thus I can't access to a filepath required by Datasource()
.
I decided to override request.upload_handlers
for my specific view, with only "django.core.files.uploadhandler.TemporaryFileUploadHandler"
because I don't need to create a subclass (for now), but I get the following error : You cannot set the upload handlers after the upload has been processed.
Here is my piece of code:
def home(request):
request.upload_handlers = ["django.core.files.uploadhandler.TemporaryFileUploadHandler"]
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['file'])
else:
form = UploadFileForm()
return render(
request,
'app/index.html',
{
'title':'HOME',
'form': form,
}
)
What am I doing wrong ? Also, should I create a subclass for a custom handler anyway ?