Skip to content

Instantly share code, notes, and snippets.

@soyuka
Created August 13, 2024 16:08
Show Gist options
  • Select an option

  • Save soyuka/f52aa1a14f86bdf5c55767f5c686a7ba to your computer and use it in GitHub Desktop.

Select an option

Save soyuka/f52aa1a14f86bdf5c55767f5c686a7ba to your computer and use it in GitHub Desktop.

Revisions

  1. soyuka created this gist Aug 13, 2024.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@

    $uploadSession = $this->metaClient->request('POST', sprintf('%s/uploads', $this->metaAppId), [
    'query' => [
    'file_name' => $mediaObject->getFilePath(),
    'file_length' => $mediaObject->getContentSize(),
    'file_type' => $mediaObject->getMimeType(),
    'access_token' => $credential->getAccessToken(),
    'appsecret_proof' => $this->secretProof($credential->getAccessToken()),
    ],
    ])->toArray();

    if (!isset($uploadSession['id'])) {
    throw new BroadcastServiceProviderException('Error while creating upload session');
    }

    $handle = $this->metaClient->request('POST', '/' . $uploadSession['id'], [ // / is important see https://github.com/symfony/symfony/issues/54332
    'headers' => [
    'file_offset' => '0',
    'content-length' => $mediaObject->getContentSize(),
    ],
    'body' => $this->mediaStorage->readStream($mediaObject->getFilePath()),
    'query' => [
    'access_token' => $credential->getAccessToken(),
    'appsecret_proof' => $this->secretProof($credential->getAccessToken()),
    ],
    ])->toArray();

    return $handle['h'];
    }