2013-04-28 5 views
0

Photologue를 설정했지만 관리자 인터페이스를 사용하지 않고 (일반) 사용자가 이미지를 업로드하는 방법을 모르겠습니다.사용자가 photologue에 이미지를 업로드 할 수있게하려면 어떻게해야합니까?

사용자가 HTML5 캔버스에서 base64 인코딩 이미지를 업로드 할 수있게하고 싶지만 첫 번째 단계에서는 사용자의 파일 시스템에서 파일을 업로드하는 것이 좋습니다.

photologue의 사진 모델을 사용하기 위해 파일을 업로드하는 방법에 대해 this general example을 수정할 수 있다고 생각합니다. "ImageModel"의 ImageField 특성 "image"를 어떻게 든 채우는 것을 의미한다고 가정합니다.

+0

. 당신은 대답을 찾았습니까? 나는 똑같은 문제가 있습니다 .. – PhilBot

+0

그래, 이걸 구현할 수 있었다. 아르 자형. 나는 대답을 쓰려고 노력할 것이다 ... – kossmoboleat

답변

0

실제로 연결된 파일 업로드 가이드를 사용하여 photologue에 적용했습니다. 캔버스 요소에서 base64 데이터 URL을 추출하고 설정했습니다. 그 값을 폼의 필드는 내가보기에 장고의 서버 측에서 해석 할 수 :

def upload_base64(request): 
    # Handle file upload 
    if request.method == 'POST': 
     form = PhotoCodeForm(request.POST, request.FILES) 

     if form.is_valid(): 
      uploaded_photo_data = base64.b64decode(request.POST['photocode']) 

      uploaded_photo_file = ContentFile(uploaded_photo_data)    

      title_str = "Untitled"    
      slug = slugify(title_str + str(datetime.now())) 

      uploaded_photo = Photo.objects.create(image = default_storage.save(slug, uploaded_photo_file), 
              title = slug, 
              title_slug = slug) 

      name_upload_gallery = "user-upload-queue"      

      try: 
       upload_gallery = Gallery.objects.get(title_slug__exact=name_upload_gallery)  
      except ObjectDoesNotExist: 
       return HttpResponseBadRequest('<html><body><p>The gallery "'+name_upload_gallery+'" does not exist.</p></body></html>') 

      upload_gallery.photos.add(uploaded_photo) 

      # Redirect to the photo gallery after POST 
      return HttpResponseRedirect('/canvas/') 
     else: 
      return HttpResponseBadRequest('<html><body><p>The entered data was not correct.</p></body></html>') 
    else: 
     form = PhotoCodeForm() # A empty, unbound form 

    return render_to_response(
     'photologue_upload/upload_base64.html', 
     {'form': form}, 
     context_instance=RequestContext(request) 
    ) 

upload_base64.html는 base64로 문자열에 붙여 필드 photocode을 가진 매우 단순한 형태입니다

관련 문제