2016-09-27 15 views
0

심포니 REST의 새로운 기능입니다. 우리 프로젝트에서는 ng-upload를 사용하여 이미지를 업로드합니다. 아래 코드는 그 일을 담당하는 코드입니다.ng-flow 404 오류가 발생했습니다.

// HTML

<div style="float: left; margin-top: 7px; width: 220px;" permission-roles="['ROLE_UNIT_WRITE']" flow-init="{target: getFlowJsTarget(), testChunks:false, headers: getFlowJsHeaders()}" flow-file-added="!!{jpg:1,jpeg:1}[$file.getExtension()]" flow-files-submitted="$flow.upload()" flow-file-success="$file.msg = $message"></div> 

// 컨트롤러 (프론트 엔드)

$scope.getFlowJsTarget = function() { 
    return Routing.generate('api_1_post_unit_photo', {id: $scope.unit.id}); 
}; 

$scope.getFlowJsHeaders = function() { 
    return {'X-XSRF-TOKEN': $cookies['XSRF-TOKEN']}; 
}; 

$scope.getUnitPhotoUrl = function(unit) { 
    return Routing.generate('api_1_get_unit_photo', {id: unit.id}); 
}; 

// 백엔드 코드 - UnitController.php

public function getUnitPhotoAction(Request $request, $id) 
{ 
    $unit = $this->getOr404($id); 

    $response = new Response(); 

    if ($unit && $unit->getPhoto()) { 
     $response->headers->set('Cache-Control', 'private'); 
     $response->headers->set('Content-type', 'image/jpeg'); 
     $response->headers->set('X-Accel-Redirect', '/unit-photos/'.$unit->getPhoto()); 

    } else { 
     $response->setStatusCode(404); 
    } 

    return $response; 
} 

public function getUnitPhotosAction(Request $request, $id) 
{ 
    $this->getOr404($id); 

    $flowJsHelper = $this->get('isf.flow_js_helper'); 

    if ($flowJsHelper->checkChunk()) { 
     return new JsonResponse(null, 200); 
    } else { 
     return new JsonResponse(null, 404); 
    } 
} 
public function postUnitPhotoAction(Request $request, $id) 
{ 
    $unit = $this->getOr404($id); 

    $flowJsHelper = $this->get('isf.flow_js_helper'); 
    $flowJsHelper->saveChunk(); 

    $data = [ 
     'success' => true, 
    ]; 

    $unitPhotoPath = $this->container->getParameter('kernel.root_dir').'/../web/uploads/unit-photos'; 
    $fileName = $unit->getId().'.jpg'; 

    if ($flowJsHelper->validateFile() && $flowJsHelper->save($unitPhotoPath.'/'.$fileName)) { 
     $data['finished'] = true; 
     $unit->setPhoto($fileName); 
     $this->getHandler()->persist($unit, false); 
    } 

    return new JsonResponse($data); 
} 

//FlowJSHelper.php

public function checkChunk() 
{ 
    return $this->filesystem->exists($this->getChunkPath($this->getParameter('flowChunkNumber'))); 
} 

public function saveChunk() 
{ 
    /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */ 
    $file = $this->getRequest()->files->get('file'); 
    $chunkFile = $this->getChunkPath(); 
    $file->move(dirname($chunkFile), basename($chunkFile)); 
} 

public function getChunkPath($index = null) 
{ 
    if (null === $index) { 
     $index = $this->getParameter('flowChunkNumber'); 
    } 

    return $this->tempDir . DIRECTORY_SEPARATOR . $this->getParameter('flowIdentifier') . '_' . $index; 
} 

오류 this과 같은 오류가 발생합니다.

겨 흐름-standalone.js : 1249 GET http://localhost:30080/api/v1/units/5732fa2dec045be8448b457d/photos?flowChu ... st1jpg & flowFilename = test1.jpg & flowRelativePath = test1.jpg & flowTotalChunks =은 (찾을 수 없음) (1) (404)

+0

방금 ​​간과했는지 모르겠지만 js 클라이언트 응용 프로그램에서 사용하는 Symfony 함수 인'Routing.generate'가 아닌가요? 그러나 아마도 자신 만의 프론트 엔드 구현을 사용하고있을 것이라고 생각합니다. 올바른 것으로 가정합니다. – kvetis

+0

예. 당신 말이 맞아요. – Pradeepb

+0

좋아, 이제 더 자세히 파고 들었어, Symfony JS 번들, 정리를위한 thx. – kvetis

답변

1

그것은 당신처럼 보인다 전송 및 GET 요청입니다. 이미지를 업로드하려고 할 때 POST 요청을 보내지 않습니까?

서버가 GET 또는 POST 요청을 기대합니까? 기타 구성

flow-init="{testChunks:false}" 

와 함께 testChunks:false를 추가

봅니다 그래서 NG-흐름은 GET 요청을 보내지 않습니다.

+0

나는 물음표를 [여기] (https://github.com/flowjs/ng-flow)에 갔다. 나는'$ flow.upload()'가 그렇게 할 것이라고 믿는다. 내가 틀렸다면 나를 바로 잡아라. – Pradeepb

+0

그래서 서버가 POST 요청을 기다리고 있습니까? –

+0

flow-init에서 testChuncks config를 false로 설정할 수 있습니까? –

관련 문제