【问题标题】:File upload using http request in Extbase, TYPO3 CMS在 Extbase、TYPO3 CMS 中使用 http 请求上传文件
【发布时间】:2019-11-05 13:24:13
【问题描述】:

我们想使用 http 请求将文件上传到 TYPO3 9 中的某个 api 端点。

【问题讨论】:

    标签: file-upload typo3 httprequest extbase


    【解决方案1】:

    文件上传可以使用 \TYPO3\CMS\Core\Http\RequestFactoryTYPO3

    $filePath = '/var/www/html/MyTypo3Project/Image.png';
    $username = 'test';
    $password = 'test';
    
    $multipart = [
        // File Parameter
        [
            'name'     => 'Image', //Api side parameter name
            'contents' => fopen(realpath($filePath), 'r'), 
            'filename' => 'MyCustomName.png' // Custom filename
        ],
    
        //Other Parameters
        [
            'name'     => 'custom_param',
            'contents' => 'custom_param_value'
        ]
    ];
    
    // Request options along with auth header
    $additionalOptions = [
        'auth' => [$username, $password],
        'multipart' => $multipart,
    ];
    
    $requestFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\RequestFactory::class);
    $response = $requestFactory->request(
        $url, // Api Endpoint Url
        'POST', 
        $additionalOptions // Passing the additional options
    );
    

    【讨论】:

      猜你喜欢
      • 2013-04-30
      • 2012-12-13
      • 2017-07-26
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多