首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ng-flow抛出404错误

ng-flow抛出404错误
EN

Stack Overflow用户
提问于 2016-09-27 10:59:42
回答 1查看 234关注 0票数 0

我是新来的。在我们的项目中,我们使用ng-上传来上传图像。下面是对此负责的代码段。

// HTML

代码语言:javascript
复制
<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>

// in控制器(前端)

代码语言:javascript
复制
$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

代码语言:javascript
复制
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

代码语言:javascript
复制
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;
}

错误我正在变得像

ng-flow-standalone.js:1249 GET http://localhost:30080/api/v1/units/5732fa2dec045be8448b457d/photos?flowChu…st1jpg&flowFilename=test1.jpg&flowRelativePath=test1.jpg&flowTotalChunks=1 404 (未找到)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-27 12:46:09

看起来你是在发送和接收请求。当你试图上传图片时,你不应该发送一个帖子请求吗?

您的服务器需要GET请求还是POST请求?

尝试将testChunks:false与其他配置一起添加

代码语言:javascript
复制
flow-init="{testChunks:false}" 

这样ng流就不会发送GET请求。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39722926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档