'latest', 'endpoint' => $awsEndpoint, 'region' => $awsRegion, ]; if ($awsKey && $awsSecret) { $clientConfig['credentials'] = [ 'key' => $awsKey, 'secret' => $awsSecret, ]; } $s3 = new Aws\S3\S3Client($clientConfig); // The @uppy/aws-s3 plugin sends `{ method, key }` per operation. // This example only handles PUT (PutObject) — multipart is disabled client-side. $body = json_decode(file_get_contents('php://input')); if (!is_object($body)) { http_response_code(400); header('content-type: application/json'); echo json_encode(['error' => 'Invalid or empty JSON body']); exit; } $method = $body->method ?? 'PUT'; $key = $body->key ?? null; if ($method !== 'PUT' || !$key) { http_response_code(400); header('content-type: application/json'); echo json_encode(['error' => 'Only PUT requests with a key are supported']); exit; } $command = $s3->getCommand('putObject', [ 'Bucket' => $bucket, 'Key' => "{$directory}/{$key}", ]); $request = $s3->createPresignedRequest($command, '+5 minutes'); header('content-type: application/json'); // signRequest expects a `{ url }` response — no method/fields/headers. echo json_encode([ 'url' => (string) $request->getUri(), ]);