2017-07-17 92 views
1

我有這個應該上傳文件的api。該代碼旨在查找上傳文件的位置,在$request->files中,但該變量爲空。相反,我在$content中找到它的字符形式( )。這種行爲是否有缺陷或我缺少什麼? 我檢查了composer.json,但沒有上傳(Vich或DoctrineExtensions)軟件包,也沒有配置。我可以設置其中一個,但我不知道目前的行爲是否是錯誤的,或者以前的開發人員比我更瞭解這方面的情況?作爲blob上傳的文件

爲了記錄在案,我有DoctrineExtensions - Uploadable

MyApp\FileBundle\Entity\File: 
    type: entity 
    table: file_records 
    repositoryClass: MyApp\FileBundle\Repository\FileRepository 

    id: 
     id: 
      type: integer 
      generator: 
       strategy: AUTO 

    fields: 

     path: 
      name: path 
      type: string 

     name: 
      name: string 
      type: string 

     mimeType: 
      name: mimeType 
      type: string 
      nullable: true 

     size: 
      name: size 
      type: decimal 
      nullable: true 

     initialName: 
      name: initial_name 
      type: string 

詩File類的YAML文件看起來類似於一個:將文件都應該是作爲文件保存在數據庫中沒有一個斑點。

回答

0

它看起來像客戶端發送文件在一個典型的HTTP請求的正文,而不是使用多部分請求。 Symfony的$request->files(並且一般而言,所有使用PHP的$_FILES的內容)都只適用於多部分請求。

你可以,解決您的客戶自己做類似的東西送(由PHP提供的安全保護和福利)多部分請求或處理的原始內容:

// Be careful to check that the real content is not PHP or something harmful this before 
file_put_contents('/path/to/myimage.png', $request->getContent());