# How to Use Pre-Signed URL in PHP with Stook

You can generate **pre-signed URLs** with the **AWS SDK for PHP** to securely access or share objects stored in **Medianova Stook Object Storage**. Pre-signed URLs allow time-limited access without exposing your credentials.

***

### Prerequisites

* PHP installed on your system
* AWS SDK for PHP included in your project
* Medianova Stook credentials (Access Key, Secret Key, Endpoint)

***

### Example: Generate a Pre-Signed URL

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

use Aws\S3\S3Client;  
use Aws\S3\Exception\S3Exception;

$bucket = "bucket";  
$key = "mykey";  

// Create a S3Client  
$s3 = new Aws\S3\S3Client([
    'endpoint' => 'https://customername.mncdn.com',
    'profile' => 'medianova',
    'version' => 'latest',
    'region' => 'us-east-1',
    'use_path_style_endpoint' => true
]);

$cmd = $s3->getCommand('GetObject', [
    'Bucket' => $bucket,
    'Key'    => $key,
]);

$request = $s3->createPresignedRequest($cmd, '+20 minutes');  

$presignedUrl = (string) $request->getUri();  
echo $presignedUrl;
```

***

### How It Works

1. Define your **bucket** and **object key**.
2. Create an **S3Client** with your Stook endpoint and credentials.
3. Use the `getCommand` method to specify the operation (e.g., `GetObject`).
4. Generate a pre-signed URL with `createPresignedRequest`.
5. Share or use the generated URL to access the object for a limited time.

***

### Troubleshooting / FAQ

* **Expired URL:** Check the validity time (`+20 minutes`, `+1 hour`, etc.).
* **Access denied:** Verify bucket policy and Stook credentials.
* **Invalid endpoint:** Ensure your Stook endpoint matches your account.

***

### References

* [AWS SDK for PHP Documentation](https://docs.aws.amazon.com/aws-sdk-php/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://clients.medianova.com/products/object-storage-stook/integration-and-usage-guides/how-to-use-pre-signed-url-in-php-with-stook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
