'latest', 'endpoint' => $awsEndpoint, 'region' => $awsRegion, ]); // Retrieve data about the file to be uploaded from the request body. $body = json_decode(file_get_contents('php://input')); $filename = $body->filename; $contentType = $body->contentType; // Prepare a PutObject command. $command = $s3->getCommand('putObject', [ 'Bucket' => $bucket, 'Key' => "{$directory}/{$filename}", 'ContentType' => $contentType, 'Body' => '', ]); $request = $s3->createPresignedRequest($command, '+5 minutes'); header('content-type: application/json'); echo json_encode([ 'method' => $request->getMethod(), 'url' => (string) $request->getUri(), 'fields' => [], // Also set the content-type header on the request, to make sure that it is the same as the one we used to generate the signature. // Else, the browser picks a content-type as it sees fit. 'headers' => [ 'content-type' => $contentType, ], ]);