I'm getting binary response from third party API via HTTP CLIENT in Symfony
How to convert that response to a UplodedFile Object.
Please suggest a good way to do this.
I'm getting binary response from third party API via HTTP CLIENT in Symfony
How to convert that response to a UplodedFile Object.
Please suggest a good way to do this.
Copyright © 2021 Jogjafile Inc.
You can't use the
UploadedFileclass, since that requires a file path and will throw an error (onmove) if you try to pass it a path to a file that wasn't uploaded via the $_FILES array.Alternatively, you can use Symfony's
Fileclass (UploadedFileextendsFile), but that also requires a file path. So you'll need to convert the response to a (temporary) file, for example using the class below.Since this class extends
File, you can validate instances of it using the Symfony Validator and callmoveon it, just as you would with anUploadedFile.And use it like this:
$tmpFile = new TmpFile((string) $response->getContent());