I am trying to write a view that will take a file uploaded via form, pass it to an ftp method and save it on an ftp server. However I am running into problems when with the file object that gets passed to the ftp method.
This is my view: def order_prints(request, object_id): p = get_object_or_404(Project, pk=object_id) d = datetime.now() def ftp_upload(file, ftp): CONTENT_TYPES = ['text'] t = file.content_type.split('/')[0] if t in CONTENT_TYPES: ftp.storlines("STOR", file, open(file)) else: ftp.storbinary("STOR", file, open(file, "rb"), 1024) if not request.method =="POST": form = ReproOrderForm() return render_to_response( 'projects/printorderform.html', {'form': form, "p": p}, context_instance = RequestContext(request, object_id), ) form = ReproOrderForm(request.POST, request.FILES) if not form.is_valid(): pass if form.is_valid(): file = request.FILES["file"] filename = file.name description = request.POST["description"] delivery = request.POST["delivery"] reprofirm = request.POST["reprofirm"] due_by = request.POST["due_by"] rf = ReproFirm.objects.get(id=reprofirm) ftp = ftplib.FTP(rf.ftp_server, rf.ftp_username, rf.ftp_password) ftp_upload(file, ftp) f = ReproOrder(project=p, user=request.user, filename=filename, reprofirm=reprofirm, due_by=due_by, pub_date=datetime.now()) f.save() ftp.quit() return HttpResponseRedirect('/projects/%s/' % object_id) So when I run this, I get: Exception Value: coercing to Unicode: need string or buffer, InMemoryUploadedFile found Which leads me to believe that I need to modify the file object before I pass it to the ftp method. Unfortunately, I am stuck. Any pointers? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---