This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
xd_2723548
I try to create images from the backend October CMS when adding a model using a third-party API by clicking on the button and return the response of each image to the File Upload widget (similar to Dropzone).
Question: How to return the answer image and immediately attach to the dropzone field? So that after saving the model, the field is attached through a relation.
Request from the button:
<button data-request="onMakeScreenshots" id="screenshots" data-request-data="url: 'http://site.ru/'" class="btn btn-primary">Создать скриншоты</button>
The controller method of this model:
<pre><code>
public function onMakeScreenShots() {
$url = post('url');
$client = new Client();
$request = $client->get('http://mini.s-shot.ru/' . '1280x800' . '/' . '1280' . '/' . '/jpeg/?' . $url);
$response = $request->getBody();
$screenshot_name = str_random(40) . '.jpg';
$file = (new File)->fromData($response, $screenshot_name);
return [
'#FileUpload-formScreenshots-screenshots' => $file
];
}
</code></pre>
The binary code is returned, I try to create a file with the name and transfer it to the field with a dropzone, but this does not work.
1-1 of 1