2009-11-21 2 views
0

업로드 이미지에 플렉스와 장고를 결합하는 방법을 아는 사람이 있습니까? Flex에서 fileRefenrece를 사용했지만 장고에서보기로 relat하는 방법을 모르겠습니다.플렉스 및 장고를 사용하여 이미지 업로드

감사합니다.

[편집] 저는 flex와 django를 사용하여 사람들이 로그인하고있는 일부 사이트 (예 : 인턴 orkut)와 같은 사이트를 만듭니다. 서버 측에서 필자의 뷰, 모델 등을 클라이언트 측에서 빌드하고, 플렉스 및 함수 및 이벤트에서의 설계, 특정 URL 및 뷰와 함께 HTTPService를 사용하여 장고를 호출한다. 예를 들어 버튼을 클릭하면 HttpService myHttpService.send()를 호출하고 필요한 매개 변수를 내보기에 제공하고 반환 된 xml_response를 서버에서 가져 와서 화면에 표시합니다. 그러나 기록 된 사람들이 자신의 onw 프로필 사진 (현재 서버의 폴더에있는 사진을 변경하도록 허용하고 이메일을 보내고 변경할 때 수동으로 변경 사항을 보내야 함)을 허용하고 싶습니다. 필자는 FileReference를 사용하여 장고보기/URL을 호출하려고했지만 어떻게해야할지 모르겠다. 나는 인터넷에서 그걸 발견하지 못한다. 그래서 누군가가 사진/파일을 장고와 플렉스를 사용하여 업로드하는 법을 안다면, 어떻게 도움이 될 것인가?

내 영어 실력에 감사드립니다.

Exemple는 로그 아웃 (아이디 년대와 이름은 포르투갈어에) :

내보기 (main.py) :

@xml_view 
def login(request, xml_resposta, xml_erros): 
    params = request.POST or request.GET 
    nome_usuario = params.get('usuario') 
    senha = params.get('senha') 
    sessao = Sessao.cria_autenticado(nome_usuario, senha) 
    xml_resposta.addChild(xml.sessao_id(sessao.get_id())) 
    return xml_resposta 

url.py :에

url(r'^logout/$', 'main.logout'), 

내 HTTPService를 플렉스 :

<mx:HTTPService id="logoutRequest" url="/logout/" resultFormat="e4x" method="POST"> 
    <mx:request xmlns=""> 
     <sessao{parentApplication.getIdSessao()}/sessao> 
    </mx:request> 

</mx:HTTPService> 

로그 아웃 버튼을 클릭하십시오. logoutRequest.send()를 호출합니다.

+0

매우 모호한 질문입니다. 이들은 완전히 다른 두 가지 기술이므로, 어떻게 연결되는지, 요청이 어떻게 이루어지는 지 등을 알려주십시오. – jkp

답변

1

Flex FileReference 객체는 파일을 일반 형식의 게시물처럼 보이게 URL에 게시합니다. 따라서 장고의 일반적인 파일 업로드 기능을 사용할 수 있습니다 Flex에서 업로드를 처리 할 수 ​​있습니다. 다음은 여러면에서 순진하지만 기본 배관을 보여

플렉스 :

def receive_file(request): 
    received_file = request.FILES['from_flex'] 
    destination = open('recieved_file.jpg', 'wb+') 
    # naively save the file to disk in this case: 
    file_data = received_file.read() 
    destination.write(file_data) 
    destination.close() 
    return HttpResponse() 
:

private var fileRef:FileReference; 

private function uploadFile():void 
{ 
    fileRef = new FileReference(); 
    fileRef.browse(); 
    fileRef.addEventListener(Event.SELECT, postFile); 
    fileRef.addEventListener(ProgressEvent.PROGRESS, uploadProgress); 
    fileRef.addEventListener(Event.COMPLETE, uploadComplete); 
    fileRef.addEventListener(IOErrorEvent.IO_ERROR, ioError); 
} 

private function postFile(event:Event):void 
{ 

    var req:URLRequest = new URLRequest('http://yourserver/yourapp/upload'); 
    fileRef.upload(req, 'from_flex'); // 'from_flex' is the key you use to refer to the file in django's request.FILES dict 
} 

private function uploadProgress(event:ProgressEvent):void 
{ 
    trace('progress'); 
} 

private function uploadComplete(event:Event):void 
{ 
    trace('done'); 
} 

private function ioError(event:IOErrorEvent):void 
{ 
    trace('error: '+event.toString()); 
} 

장고에서 그냥 파일을 수신하고 당신이 원하는 것이 무엇이든 뷰를 필요로 해를

urls.py 파일에 항목을 추가하여 위의보기를 일부 URL을 통해 공개해야합니다. 업로드 된 파일 처리에 대한 자세한 내용은 django 문서를 참조하십시오.

관련 문제