

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Amazon S3 prefirmato POSTs con la versione 3 AWS SDK per PHP
<a name="s3-presigned-post"></a>

Proprio come quelli prefirmati URLs, i prefirmati POSTs consentono di concedere l'accesso in scrittura a un utente senza fornire loro AWS credenziali. [I moduli POST prefirmati possono essere creati con l'aiuto di un'istanza di AWSS3 V4. PostObject](https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.PostObjectV4.html)

Gli esempi seguenti mostrano come:
+ [Ottieni i dati per un modulo di caricamento S3 Object POST utilizzando V4. PostObject](https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.PostObjectV4.html)

Tutto il codice di esempio per il AWS SDK per PHP è disponibile [qui](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code). GitHub

## Credenziali
<a name="examplecredentials"></a>

**Nota**  
`PostObjectV4`non funziona con credenziali provenienti da. AWS IAM Identity Center

Prima di eseguire il codice di esempio, configurate AWS le vostre credenziali, come descritto in. [Autenticazione con l' AWS utilizzo AWS SDK per PHP della versione 3](credentials.md) Quindi importate il file AWS SDK per PHP, come descritto in[Installazione della AWS SDK per PHP versione 3](getting-started_installation.md).

## Crea PostObject V4
<a name="create-postobjectv4"></a>

Per creare un'istanza di `PostObjectV4` è necessario fornire quanto segue:
+ istanza di `Aws\S3\S3Client` 
+ bucket
+ array associativo dei campi di input del modulo
+ serie di condizioni delle politiche (vedi [Policy Construction](https://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTForms.html) nella Guida per l'utente di Amazon Simple Storage Service)
+ stringa relativa al periodo di scadenza per la policy (opzionale, il valore predefinito è un'ora).

 **Importazioni** 

```
require '../vendor/autoload.php';

use Aws\S3\PostObjectV4;
use Aws\S3\S3Client;
```

 **Codice di esempio** 

```
require '../vendor/autoload.php';

use Aws\S3\PostObjectV4;
use Aws\S3\S3Client;

$client = new S3Client([
    'profile' => 'default',
    'region' => 'us-east-1',
]);
$bucket = 'amzn-s3-demo-bucket10';
$starts_with = 'user/eric/';
$client->listBuckets();

// Set defaults for form input fields.
$formInputs = ['acl' => 'public-read'];

// Construct an array of conditions for policy.
$options = [
    ['acl' => 'public-read'],
    ['bucket' => $bucket],
    ['starts-with', '$key', $starts_with],
];

// Set an expiration time (optional).
$expires = '+2 hours';

$postObject = new PostObjectV4(
    $client,
    $bucket,
    $formInputs,
    $options,
    $expires
);

// Get attributes for the HTML form, for example, action, method, enctype.
$formAttributes = $postObject->getFormAttributes();

// Get attributes for the HTML form values.
$formInputs = $postObject->getFormInputs();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>PHP</title>
</head>
<body>
<form action="<?php echo $formAttributes['action'] ?>" method="<?php echo $formAttributes['method'] ?>"
      enctype="<?php echo $formAttributes['enctype'] ?>">
    <label id="key">
        <input hidden type="text" name="key" value="<?php echo $starts_with ?><?php echo $formInputs['key'] ?>"/>
    </label>
    <h3>$formInputs:</h3>
    acl: <label id="acl">
        <input readonly type="text" name="acl" value="<?php echo $formInputs['acl'] ?>"/>
    </label><br/>
    X-Amz-Credential: <label id="credential">
        <input readonly type="text" name="X-Amz-Credential" value="<?php echo $formInputs['X-Amz-Credential'] ?>"/>
    </label><br/>
    X-Amz-Algorithm: <label id="algorithm">
        <input readonly type="text" name="X-Amz-Algorithm" value="<?php echo $formInputs['X-Amz-Algorithm'] ?>"/>
    </label><br/>
    X-Amz-Date: <label id="date">
        <input readonly type="text" name="X-Amz-Date" value="<?php echo $formInputs['X-Amz-Date'] ?>"/>
    </label><br/><br/><br/>
    Policy: <label id="policy">
        <input readonly type="text" name="Policy" value="<?php echo $formInputs['Policy'] ?>"/>
    </label><br/>
    X-Amz-Signature: <label id="signature">
        <input readonly type="text" name="X-Amz-Signature" value="<?php echo $formInputs['X-Amz-Signature'] ?>"/>
    </label><br/><br/>
    <h3>Choose file:</h3>
    <input type="file" name="file"/> <br/><br/>
    <h3>Upload file:</h3>
    <input type="submit" name="submit" value="Upload to Amazon S3"/>
</form>
</body>
</html>
```