# React native api gateway for cloudinary uploads

> Sign Cloudinary uploads at the edge instead of shipping API secrets in the app bundle. For "react native api gateway for cloudinary uploads", store CLOUDINARY_BASIC_AUTH in Secret Vault, call https://api.cloudinary.com/v1_1/{{secrets.CLOUDINARY_CLOUD_NAME}}/resources/image from a Worker, and let React Native hit only https://realcomposer.com/v1/workspace/best-api-gateway-cloudinary-react-native with an rc_live_ client token.

- Canonical page: https://realcomposer.com/recipes/best-api-gateway-cloudinary-react-native
- Client platform: React Native
- Upstream services: Cloudinary
- Category: Platforms & Frameworks
- JSON version: https://realcomposer.com/recipes/best-api-gateway-cloudinary-react-native.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=best-api-gateway-cloudinary-react-native&via=agent

## Problem: CORS blocks Cloudinary in React Native

Low-code React Native tools expose connector tokens in shared workspaces, so Cloudinary credentials leak to every editor.

- Browser console CORS errors blocking launches
- Editors pasting secrets into reusable components
- Inability to test locally without disabling security

## Solution steps

1. **Store upstream credentials in Secret Vault**: Store CLOUDINARY_BASIC_AUTH in the vault. React Native never embeds the raw secret, only a revocable rc_live_ client token.

2. **Target the real upstream URL**: Point step cloudinary at https://api.cloudinary.com/v1_1/{{secrets.CLOUDINARY_CLOUD_NAME}}/resources/image with GET. Add output mapping fields that mirror the JSON contract your screen already expects. Leave cache TTL at 0 when each response is user-specific (include userId or record id in query params before enabling cache).

3. **Call from React Native**: Allowed origins on the token should list every React Native host that calls this URL.

```
const res = await fetch('https://realcomposer.com/v1/workspace/best-api-gateway-cloudinary-react-native', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "React native api gateway for cloudinary uploads",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "cloudinary",
      "upstreamUrlTemplate": "https://api.cloudinary.com/v1_1/{{secrets.CLOUDINARY_CLOUD_NAME}}/resources/image",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Basic {{secrets.CLOUDINARY_BASIC_AUTH}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "publicId",
        "sourcePath": "resources.0.public_id",
        "type": "string",
        "sourceStep": "cloudinary"
      },
      {
        "targetPath": "format",
        "sourcePath": "resources.0.format",
        "type": "string",
        "sourceStep": "cloudinary"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/best-api-gateway-cloudinary-react-native" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_best-api",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "best-api-gateway-cloudinary-react-native"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "publicId": "sample",
  "format": "sample"
}
```

## FAQ

### Which Cloudinary credential belongs in the vault for this pipeline?

Log request IDs for best-api-gateway-cloudinary-react-native, not raw Cloudinary payloads, because upstream bodies may include PII.

### What cache key does RealComposer use?

Cache key for best-api-gateway-cloudinary-react-native: internal edge-cache path plus sorted query. Identical params hit; vary userId per user.

### How do I rotate upstream credentials?

Upstream steps in best-api-gateway-cloudinary-react-native honor timeoutMs and optional fallback JSON without leaking secrets.
