Esempio n. 1
0
def plupload_service(request):
	media_extension = 'file'
	img_ext = ['jpg','png','bmp','jpeg', 'tiff']
	if request.method == 'POST':
		print request.POST
		extension = request.POST['name'].split('.')[-1]
		if extension in img_ext:
			media_extension = 'img'
		with open(MEDIA_ROOT+ 'media/' +request.FILES['file'].name, 'wb+') as destination:
			for chunk in request.FILES['file'].chunks():
				destination.write(chunk)
			inst = Content_Media(name = request.FILES['file'].name, media_file = File(destination),media_type = media_extension)
			inst.save()
		
	else:
		pass
	return HttpResponse()