# Application file storage (`applicationfilestorage`)

Tenant table that controls where uploaded files are stored and how public URLs are built.

## Columns

| Column | Description |
|--------|-------------|
| `StorageRootPath` | Absolute uploads folder on the machine running the API (e.g. `/home/skcsolut/public_html/sk-cart/uploads/`) |
| `PublicUrlPrefix` | Web path prefix (default `/uploads`) |
| `PublicAssetBaseUrl` | Optional origin for browser URLs (ApplicationId 3 seed: `https://skcart.skcsolution.in`) |
| `RemoteFileApiBaseUrl` | When set, localhost dev API proxies uploads/deletes/downloads to this API base (e.g. `https://devapi.skcsolution.in/api/v1`) |
| `StorageClientUrl` | `ClientUrl` sent on proxied requests (e.g. `skcartadmin.skcsolution.in`) |

## Migrations

Run on each tenant database:

```bash
# From SKCSdbScripts/Migrations/alter_applicationfilestorage_remote_columns.sql
```

Re-run or apply seed:

```bash
# SKCSdbScripts/seeds-data/tbl_applicationfilestorage_seed.sql
```

## Enable localhost → server file proxy (ApplicationId 3)

`PublicAssetBaseUrl` is seeded as `https://skcart.skcsolution.in`. Set proxy fields manually:

```sql
UPDATE applicationfilestorage SET
  RemoteFileApiBaseUrl = 'https://YOUR_SERVER_API/api/v1',
  StorageClientUrl = 'skcartadmin.skcsolution.in'
WHERE ApplicationId = 3 AND DeleteInd = 0;
```

Requirements:

- Local backend can reach `RemoteFileApiBaseUrl`
- Master `client` row for `StorageClientUrl` uses the same tenant database as local dev
- Remote API runs on Linux so `StorageRootPath` is the real server disk

## Image URL shape (app 3)

`https://skcart.skcsolution.in/uploads/{FilePath}`

Example: `https://skcart.skcsolution.in/uploads/product-images/ec_product/12/1730000000-123456.jpg`

## ApplicationId resolution (no `.env` required for storage)

Backend resolves `ApplicationId` in order:

1. Request body/query `ApplicationId`
2. Master `client` row for `ClientUrl`
3. Single active row in `applicationfilestorage` for the tenant

`REACT_APP_APPLICATION_ID` remains an optional fallback for uploads from the React app.
