Json Symfony4(API)-尝试使用请求上载文件->;文件->;all()给我一个空结果
我正在尝试使用symfony 4中的API上传一个文件,我正在使用RESTLET工具发送我的文件,但我得到的结果是200 OK,但结果为空 内容类型:文本/纯文本 方法:邮寄 文件大小:1ko 代码:Json Symfony4(API)-尝试使用请求上载文件->;文件->;all()给我一个空结果,json,api,symfony4,Json,Api,Symfony4,我正在尝试使用symfony 4中的API上传一个文件,我正在使用RESTLET工具发送我的文件,但我得到的结果是200 OK,但结果为空 内容类型:文本/纯文本 方法:邮寄 文件大小:1ko 代码: <?php namespace App\Controller\Api\Dossier; use App\Entity\Dossier\Fichier; use App\Helpers\Constant\ErrorMessage; use Symfony\Component\HttpFoun
<?php
namespace App\Controller\Api\Dossier;
use App\Entity\Dossier\Fichier;
use App\Helpers\Constant\ErrorMessage;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/{db}/fichier")
*/
class ApiFichierController extends ApiController
{
/**
* @Route("/", name="api_fichier_enregistrer", methods={"POST"})
* @param Request $request
* @return JsonResponse|RedirectResponse
*/
public function retrieveAction(Request $request){
// retrieve the file with the name given in the form.
$filesResult = array();
$filesBag = $request->files->all();
foreach ($filesBag as $file){
$filename = $file->getClientOriginalName();
$filesResult []= array(
'path' => $file->getPathname(),
'url' => 'ddd'
);
$src = __DIR__;
$file->move( $src ,$filename );
}
return new JsonResponse($filesBag);
}
您希望使用内容类型:多部分/表单数据,以便实际上载文件
是的,我试过一次,它给了我:
警告:多部分/表单数据中缺少边界,在第0行发布未知数据
[
很抱歉,我没有得到该示例中的内容,因为我不使用表单!我应该在边界中指定什么?好的,现在我使用表单,它工作正常,谢谢你