Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support uploading to r2 and using presigned urls instead of post policy #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const nup = new NextUpload(config);

export const POST = (request: NextRequest) => nup.handler(request);

export const dynamic = 'force-dynamic';


// Optionally, if your application supports it you can run next-upload in the Edge runtime.
export const runtime = 'edge';
Expand Down Expand Up @@ -255,7 +255,8 @@ Consider setting up a cron job to run this function on a regular basis.

### Methods

- [generatePresignedPostPolicy](#gear-generatepresignedpostpolicy)
- [generatePresigned](#gear-generatepresigned)
- [defaultCorsRules](#gear-defaultcorsrules)
- [namespaceFromEnv](#gear-namespacefromenv)
- [bucketFromEnv](#gear-bucketfromenv)
- [getIdFromPath](#gear-getidfrompath)
Expand All @@ -266,17 +267,23 @@ Consider setting up a cron job to run this function on a regular basis.
- [getClient](#gear-getclient)
- [init](#gear-init)
- [bucketExists](#gear-bucketexists)
- [generatePresignedPostPolicy](#gear-generatepresignedpostpolicy)
- [generatePresigned](#gear-generatepresigned)
- [pruneAssets](#gear-pruneassets)
- [verifyAsset](#gear-verifyasset)
- [deleteAsset](#gear-deleteasset)
- [getAsset](#gear-getasset)

#### :gear: generatePresignedPostPolicy
#### :gear: generatePresigned

| Method | Type |
| ---------- | ---------- |
| `generatePresigned` | `(args: any, request: NextToolRequest or undefined) => Promise<GeneratePresigned>` |

#### :gear: defaultCorsRules

| Method | Type |
| ---------- | ---------- |
| `generatePresignedPostPolicy` | `(args: any, request: NextToolRequest or undefined) => Promise<{ postPolicy: SignedPostPolicy; }>` |
| `defaultCorsRules` | `(allowedOrigins?: string[]) => { AllowedHeaders: string[]; AllowedMethods: string[]; AllowedOrigins: string[]; ExposeHeaders: never[]; MaxAgeSeconds: number; }[]` |

#### :gear: namespaceFromEnv

Expand Down Expand Up @@ -338,11 +345,11 @@ Consider setting up a cron job to run this function on a regular basis.
| ---------- | ---------- |
| `bucketExists` | `() => Promise<boolean>` |

#### :gear: generatePresignedPostPolicy
#### :gear: generatePresigned

| Method | Type |
| ---------- | ---------- |
| `generatePresignedPostPolicy` | `(args: GeneratePresignedPostPolicyArgs, request?: NextUploadRequest or undefined) => Promise<{ postPolicy: SignedPostPolicy; }>` |
| `generatePresigned` | `(args: GeneratePresignedArgs, request?: NextUploadRequest or undefined) => Promise<GeneratePresigned>` |

#### :gear: pruneAssets

Expand Down Expand Up @@ -380,7 +387,7 @@ Consider setting up a cron job to run this function on a regular basis.
| Property | Type | Description |
| ---------- | ---------- | ---------- |
| `deleteAsset` | `'deleteAsset'` | |
| `generatePresignedPostPolicy` | `'generatePresignedPostPolicy'` | |
| `generatePresigned` | `'generatePresigned'` | |
| `getAsset` | `'getAsset'` | |
| `pruneAssets` | `'pruneAssets'` | |
| `verifyAsset` | `'verifyAsset'` | |
Expand Down
9 changes: 4 additions & 5 deletions examples/next-upload-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
"@keyv/postgres": "^1.4.10",
"@neondatabase/serverless": "^0.9.0",
"@types/node": "20.12.7",
"@types/react": "18.2.78",
"@types/react": "18.2.79",
"@types/react-dom": "18.2.25",
"bytes": "^3.1.2",
"drizzle-orm": "^0.30.8",
"eslint": "9.0.0",
"eslint-config-next": "14.2.1",
"eslint": "9.1.1",
"eslint-config-next": "14.2.2",
"keyv": "^4.5.4",
"next": "14.2.1",
"next-upload": "^0.0.30",
"next": "14.2.2",
"postgres": "^3.4.4",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 0 additions & 2 deletions examples/next-upload-example/src/app/upload/basic/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ import { NextRequest } from 'next/server';
import { nup } from './nup';

export const POST = (request: NextRequest) => nup.handler(request);

export const dynamic = 'force-dynamic';
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ import { NextRequest } from 'next/server';
import { nup } from './nup';

export const POST = (request: NextRequest) => nup.handler(request);

export const dynamic = 'force-dynamic';
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ import { NextRequest } from 'next/server';
import { nup } from './nup';

export const POST = (request: NextRequest) => nup.handler(request);

export const dynamic = 'force-dynamic';
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ import { nup } from './nup';

export const POST = (request: NextRequest) => nup.handler(request);

export const dynamic = 'force-dynamic';

export const runtime = 'edge';
2 changes: 0 additions & 2 deletions examples/next-upload-example/src/app/upload/edge/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ import { nup } from './nup';

export const POST = (request: NextRequest) => nup.handler(request);

export const dynamic = 'force-dynamic';

export const runtime = 'edge';
2 changes: 0 additions & 2 deletions examples/next-upload-example/src/app/upload/keyv/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ import { NextRequest } from 'next/server';
import { nup } from './nup';

export const POST = (request: NextRequest) => nup.handler(request);

export const dynamic = 'force-dynamic';
Loading