$ch = curl_init($url);
$data = [
'params' => json_encode([
"type" => "GENERATE",
"numImages" => 1,
"width" => 1024,
"height" => 1024,
'generateParams' => [
'query' => 'море'
]
]),
'model_id' => '4'
];
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-Key: Key '.$xKey,
'X-Secret: Secret '.$xSecret
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Ошибка: ' . curl_error($ch);
} else {
echo 'Ответ: ' . $response;
}
curl_close($ch);
"status":415,"error":"Unsupported Media Type",
"message":"Content-Type 'application/octet-stream' is not supported.",
"path":"/key/api/v1/text2image/run"
def generate(self, prompt, model, images=1, width=1024, height=1024):
params = {
"type": "GENERATE",
"numImages": images,
"width": width,
"height": height,
"generateParams": {
"query": f"{prompt}"
}
}
data = {
'model_id': (None, model),
'params': (None, json.dumps(params), 'application/json')
}
response = requests.post(self.URL + 'key/api/v1/text2image/run', headers=self.AUTH_HEADERS, files=data)
data = response.json()
return data['uuid']
$boundary = uniqid();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-Key: Key '.$xKey,
'X-Secret: Secret '.$xSecret,
"Content-Type: multipart/form-data; boundary=$boundary",
]);
$eol = "\r\n";
$params=$data['params'];
$postFields = "--$boundary$eol" .
"Content-Disposition: form-data; name=\"model_id\"$eol$eol" .
"4$eol" .
"--$boundary$eol" .
"Content-Disposition: form-data; name=\"params\"$eol" .
"Content-Type: application/json$eol$eol" .
"$params$eol" .
"--$boundary--";
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
<?php
// ...
$data = [
'params' => json_encode([
"type" => "GENERATE",
"numImages" => 1,
"width" => 1024,
"height" => 1024,
'generateParams' => [
'query' => 'море'
]
]),
'model_id' => '4'
];
// ...
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-Key: Key '.$xKey,
'X-Secret: Secret '.$xSecret,
'Content-Type: application/json' // <--- !!!
]);
// ...
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// ...
p.s. Я так понимаю из python кода он хочет мультипарт, но не понимаю как подобное реализовать в php
# ...
data = {
'model_id': (None, model),
'params': (None, json.dumps(params), 'application/json') # ??? !!!
}
# ...