# How to Use Pre-Signed URL in Node.js with Stook

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

***

### Prerequisites

* Node.js installed on your system
* AWS SDK for Node.js installed (`npm install aws-sdk`)
* Medianova Stook credentials:
  * **Access Key**
  * **Secret Key**
  * **Endpoint**

***

### Example: Generate a Pre-Signed URL

```javascript
var AWS = require('aws-sdk');

var config = {
    s3ForcePathStyle: true,
};

var credentials = new AWS.SharedIniFileCredentials({
    profile: 'medianova'
});

AWS.config.credentials = credentials;
AWS.config.update(config);

var ep = new AWS.Endpoint('customername.mncdn.com');
var s3 = new AWS.S3({endpoint: ep});

var myBucket = 'bucket';
var myKey = 'mykey';
var signedUrlExpireSeconds = 60 * 5;

var url = s3.getSignedUrl('getObject', {
    Bucket: myBucket,
    Key: myKey,
    Expires: signedUrlExpireSeconds
});

console.log(url);
```

***

### How It Works

1. Configure the AWS SDK with `s3ForcePathStyle`.
2. Use your Medianova credentials (via profile or direct configuration).
3. Define **bucket**, **object key**, and expiration time.
4. Call `getSignedUrl('getObject', {...})` to generate a URL.
5. Use or share the generated URL within its expiration time.

***

### Troubleshooting / FAQ

* **Expired URL:** Adjust `Expires` value (e.g., `60*10` for 10 minutes).
* **Access denied:** Verify bucket policy and Stook credentials.
* **Invalid endpoint:** Ensure endpoint matches your Stook account.

***

### References

* [AWS SDK for Node.js Documentation](https://docs.aws.amazon.com/sdk-for-javascript/)


---

# 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-node.js-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.
