# Send files to your users from your app

Your app makes an invoice, an export, a set of photos or a project delivery,
and your user should get it. With Culacc you upload it, share it as a link (or
let Culacc email the link), and decide when it stops working and whether the
files are deleted afterwards. The person who gets it needs no account.

## What your user gets

A share page on culacc.com with your title and message: a preview of every
file, a download button for each one, **Download all** as a ZIP, and folders
they can open. You can add a password, an expiry date, and "Can edit", which
lets them edit the files in the browser (documents, spreadsheets, PDFs, photos,
drawings, audio). If you email it, each person gets their own email, from
"Your Name via Culacc" when you give a sender name, and their replies come to
you.

## Before you start

1. Make a free Culacc account at <https://culacc.com>.
2. In **Settings → Developers**, press **New key** and tick **files:read**,
   **files:write** and **shares:write**. Keep the key on your server.
3. `npm install @culacc/sdk` (Node 18 or newer), or call the REST API from any
   language.

## Send files in one call

```js
const { Culacc } = require('@culacc/sdk');
const culacc = new Culacc({ key: process.env.CULACC_KEY });

const { share, emails } = await culacc.send([
  { name: 'invoice-1042.pdf', data: pdfBuffer },          // bytes you have in memory
  { localPath: './exports/orders-march.xlsx' },           // a file on disk, any size
], {
  to: 'client@example.com',             // or a list, up to 20; leave out to only get the link
  senderName: 'Acme Studio',
  title: 'Your March documents',
  message: 'Here are the invoice and the order export.',
  expiresInDays: 7,
  autoDelete: true,                     // delete the files when the link expires
  externalRef: 'customer-381',          // your own id, to find the share again
  folder: '/Customers/381',             // where the files go in your storage
});

console.log(share.url);       // https://culacc.com/bundle/…
console.log(emails);          // [{ email: 'client@example.com', status: 'sent' }]
```

`send()` uploads new content (in parts when it's big), then makes the share.
You can mix in files that are already in Culacc by id or path:
`culacc.send([4821, '/Contracts/acme.pdf'], { to: … })`.

## Share files and folders you already have

```js
const { share } = await culacc.shares.create({
  items: ['/Customers/381'],            // a folder: everything in it, now and later
  title: 'Acme: project files',
  canEdit: true,
  password: 'blue-river-42',
  expiresInDays: 0,                     // never expires
});
```

A shared folder is live: files you put into it later appear for your user
without a new link. That makes it a simple client portal: one folder and one
link per customer.

| Option | What it does |
|---|---|
| `items` | files and folders, by id or path (up to 200; a folder can hold any number) |
| `to`, `senderName`, `replyTo`, `message` | email it now; replies go to your account's address unless you set `replyTo` |
| `expiresInDays`, `expiresAt`, `never` | 30 days by default; `0` means never |
| `password` | asked for on the share page |
| `canEdit` | people with the link can edit the files |
| `externalRef` | your own reference, to find the share later |
| `autoDelete` | delete the files for good when the share expires or is stopped |

## Find, change and send again

```js
const { shares } = await culacc.shares.list({ externalRef: 'customer-381', status: 'active' });
const { share } = await culacc.shares.get(shares[0].id);        // items, views, downloads, recipients

await culacc.shares.update(share.id, { expiresInDays: 30, password: null });
await culacc.shares.send(share.id, 'accounts@example.com');     // the same link to someone else
await culacc.shares.addItems(share.id, ['/Customers/381/invoice-1043.pdf']);
```

## Stop sharing, and clean up

```js
await culacc.shares.revoke(share.id);                          // the link stops working at once
await culacc.shares.revoke(share.id, { deleteFiles: true });   // and its files are deleted for good
```

With `autoDelete: true` you don't have to remember: when the share expires,
Culacc deletes its files and gives the space back. Files that another active
share still holds, or that are published on the web, are kept and reported
instead, so a cleanup never breaks another link.

To delete files yourself at any time:

```js
await culacc.files.delete('/Customers/381/old-export.xlsx');                  // to the trash
await culacc.files.delete('/Customers/381/old-export.xlsx', { permanent: true }); // for good
```

## Know what happened

Webhooks tell your server about it, signed so you can check they're real:

```js
await culacc.webhooks.create({
  url: 'https://your-app.com/hooks/culacc',
  events: ['share.created', 'share.expired', 'share.revoked', 'file.deleted'],
});
```

`share.expired` carries your `externalRef`, and for an `autoDelete` share how
many files were deleted and how many bytes were freed.

## From Python, PHP or anything else

```python
import os, requests
API, H = "https://culacc.com/api/v1", {"Authorization": f"Bearer {os.environ['CULACC_KEY']}"}

share = requests.post(f"{API}/shares", headers=H, json={
    "items": ["/Customers/381"], "to": "client@example.com",
    "senderName": "Acme Studio", "expiresInDays": 7, "autoDelete": True,
}).json()["share"]
print(share["url"])
```

## Limits and costs

- Up to 200 files and folders per share, 20 addresses per email, 200 share emails a day per account
  (20 on the free plan, which also can't put links in the message), 3 a day to the same address.
- Files up to 5 TB each.
- Storage at your Culacc price (5 GB free, then €0.50 per 100 GB a month). Making shares and sending emails costs nothing extra.
- Downloads through your shares are traffic on your meter, like published files: 10 GB a month free, then €1 per TB, under
  the monthly spending limit you set. Each share shows `traffic.bytesThisMonth`; `GET /v1/shares/traffic` has the month's total.

## Reference

- [Sharing files](/developers#sharing-files) and [Deleting files](/developers#deleting-files) in the API reference
- [Upload files of any size](/developers/upload-files/)
- OpenAPI: <https://culacc.com/docs/openapi.json>
