2017-10-25 09:35
浏览 41

无法读取HTTP Foundation Symfony 3.3中的“文件”

Recently I updated a symfony project from 3.2 to 3.3. I have an issue with a simple POST with a file. The file is not in the filebag of the http foundation object Request.

public function sendAction(Request $request){
    if (!$request->files->has("image")) {
        throw new HttpException(Response::HTTP_BAD_REQUEST, 'no "image" field');

When I have a look at what it dumped, depending on the content-type of the request, I have different results :

If I use application/x-www-form-urlencoded as header, I have these dump : (sorry for pastebin links, output is too long)

If i use multipart/form-data as header, I have these dumps :

What's wrong with my script ? Am i missing a new feature or security check ?

图片转代码服务由CSDN问答提供 功能建议

最近我将symfony项目从3.2更新到3.3。 我有一个带文件的简单POST问题。 该文件不在http基础对象Request的文件包中。

  public function sendAction(Request $ request){
 dump($ request-> files); \  n dump($ request-> request); 
 dump($ request-> headers); 
 if(!$ request-> files-> has(“image”)){
 throw new HttpException  (响应:: HTTP_BAD_REQUEST,'否'图像“字段”); 

当我查看它转储的内容时, dedepending 在请求的内容类型上,我有不同的结果:

如果我使用 application / x-www-form-urlencoded 作为标题,我有这些 转储: (抱歉为pastebin链接,输出太长)

如果我使用 multipart / form-data 作为标题,我有这些转储:

我的脚本出了什么问题? 我错过了新功能或安全检查吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxiee0744 2017-10-25 09:43

    Ok it was a stupid client error. I specified the header :

    Content-type: multipart/form-data

    but it should be

    Content-type: multipart/form-data; boundary=-------------BOUNDARYUSEDINREQUEST--------------
    解决 无用
    打赏 举报

相关推荐 更多相似问题