2012-10-17 5 views
1

Backbone에서 Django 파일 업로드 시스템으로 파일을 업로드하고 싶습니다.파일을 백본에서 장고 모델로 전송

먼저 나는 https://stackoverflow.com/a/10916733/1590377 설명을 따랐습니다. 나는 FileModel을했는데 위의 표시와 함께이 정보를 가진 모델이 있습니다

def upload_file_64(request): 
    if request.method == 'POST': 

     file = cStringIO.StringIO(base64.b64decode(request.POST['data'])) 
     #method to save the file 
     response_data={"result":"ok"} 
     return HttpResponse(simplejson.dumps(response_data), mimetype='application/json') 
else: 
    response_data={"success": "No a post request"} 
    return HttpResponse(simplejson.dumps(response_data), mimetype='application/json') 
:

attributes: Object 
    data: "data:image/png;base64,iVBORw ..." 
    file: "image2012-06-12 13:36:45.png" 

지금 내가 이런 장고에 업로드 뷰를 가지고있는 URL에 모델을 저장을

하지만 장고 SISTEM 나에게주고 있다는 응답은 다음과 같습니다

"MultiValueDictKeyError at /api/upload64/↵'Key \'data\' not found in <QueryDict: {u\'base64,iVBORw0KG.... 

포스트 HTTP 요청은 다음과 같습니다

POST: 
base64,iVBORw0KG ..."} = u'' 
{"file":"Captura de pantalla de 2012-06-12 13:36:45.png","data":"data:image/png = u'' 

파일을 장고에 업로드 할 수 있도록 어떻게 수정해야합니까? 여러 플랫폼에서 파일을 업로드 할 때 멀티 파트 메서드를 사용하여 안드로이드를 구현하지만 백본을 사용하면 파일을 업로드 할 수 없습니다.

누군가이 문제를 해결할 수 있습니까?

감사합니다.

답변

0

다른 솔루션을 코딩했습니다. jquery 업로드 plugin을 사용하여 파일을 업로드하고 응답을 받았습니다.

플러그인은 다음과 같습니다 http://lagoscript.org/jquery/upload/demo?locale=en 내가 내 백본보기에 사용 된 코드는 다음과 같습니다

events : { 
    'change #file1' : 'upload' 
}, 
upload : function(){ 

    $('#file1').upload('http://192.168.0.195/api/upload/', function(res) { 
      console.log(res) 
      //now I use the res to create a model :) 
     }, 'html'); 
}, 
관련 문제