Ng-flow抛出404错误
ng-flow throws 404 error
我是symfony REST框架新手。在我们的项目中,我们使用ng-upload上传图像。下面是负责这个的代码:
//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;
}
error I ' m get like this.
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 (Not Found)
看起来您正在发送一个GET请求。当你试图上传图像时,你不应该发送POST请求吗?
您的服务器期望一个GET还是POST请求?
尝试添加testChunks:false
和其他配置
flow-init="{testChunks:false}"
相关文章:
- 为什么jasmine期望不验证是否抛出了错误
- gulp Iconify任务抛出错误TypeError:Path必须是字符串.收到false
- $(input[]).仅在firefox中出现每个抛出语法错误
- 为什么浏览器没有为语法错误抛出异常
- PHP REST服务抛出异常——希望避免控制台错误
- 为什么datetime.strptime在使用Django运行时会抛出错误
- IE9抛出错误的reactJs
- 在选项卡中使用时,Onsen UI拉钩会抛出错误
- 调用控制器后Ajax抛出错误
- 在JSON.parse Javascript中字符串化Java对象抛出错误
- jQuery在smarty代码上抛出未捕获的错误
- JSON.parse,已经在try/catch块中,仍然抛出语法错误
- 角度过滤器可以工作,但将输入视为未定义并抛出错误
- 页面上的2个表单带有JS验证-其中一个抛出电子邮件验证错误
- AngularJS控制器在注入工厂时抛出错误
- fs.statSync包含在函数中时抛出错误
- Jasmine:测试setTimeout函数会抛出一个错误
- javascript原型将错误抛出为“;Object〔Object Object〕没有方法”;
- Node.js错误抛出被认为是不好的做法,但对于TDD来说却是必不可少的
- iPhone“Go"键盘按钮导致错误抛出前发回