{"id":14957386,"url":"https://github.com/a179346/nextjs-chunk-upload-action-example","last_synced_at":"2025-07-11T07:04:56.399Z","repository":{"id":224947917,"uuid":"764666814","full_name":"a179346/nextjs-chunk-upload-action-example","owner":"a179346","description":"An example of utilizing the nextjs-chunk-upload-action library","archived":false,"fork":false,"pushed_at":"2024-04-04T17:18:21.000Z","size":527,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-05T15:23:50.863Z","etag":null,"topics":["chunk-upload","next-js","nextjs-chunk-upload-action","server-action"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a179346.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-28T13:52:40.000Z","updated_at":"2024-10-13T08:09:41.000Z","dependencies_parsed_at":"2024-03-03T08:21:18.095Z","dependency_job_id":"6b756c1c-21ce-4dc1-9801-802e4b3581ab","html_url":"https://github.com/a179346/nextjs-chunk-upload-action-example","commit_stats":null,"previous_names":["a179346/nextjs-chunk-upload-action-demo","a179346/nextjs-chunk-upload-action-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/a179346/nextjs-chunk-upload-action-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a179346%2Fnextjs-chunk-upload-action-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a179346%2Fnextjs-chunk-upload-action-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a179346%2Fnextjs-chunk-upload-action-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a179346%2Fnextjs-chunk-upload-action-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a179346","download_url":"https://codeload.github.com/a179346/nextjs-chunk-upload-action-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a179346%2Fnextjs-chunk-upload-action-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264752735,"owners_count":23658703,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chunk-upload","next-js","nextjs-chunk-upload-action","server-action"],"created_at":"2024-09-24T13:14:49.664Z","updated_at":"2025-07-11T07:04:56.372Z","avatar_url":"https://github.com/a179346.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## nextjs-chunk-upload-action-example\n\n\u003e An example of utilizing the [nextjs-chunk-upload-action](https://github.com/a179346/nextjs-chunk-upload-action) library.\n\n## Start\n\n```sh\nnpm run dev\n```\n\n## Usage\n\n```ts\n// upload-form.tsx\n\n'use client';\n\nimport { ChunkUploader } from 'nextjs-chunk-upload-action';\n\nimport { chunkUploadAction } from '@/server/chunk-upload-action';\n\nexport function UploadForm() {\n  const handleFormAction = (formData: FormData) =\u003e {\n    const file = formData.get('file') as File;\n    if (!file) return;\n\n    const uploader = new ChunkUploader({\n      file,\n      onChunkUpload: chunkUploadAction,\n      metadata: { name: file.name },\n      onChunkComplete: (bytesAccepted, bytesTotal) =\u003e {\n        console.log('Progress:', `${bytesAccepted} / ${bytesTotal}`);\n      },\n      onError: error =\u003e {\n        console.error(error);\n      },\n      onSuccess: () =\u003e {\n        console.log('Upload complete');\n      },\n    });\n\n    uploader.start();\n  };\n\n  return (\n    \u003cform className=\"flex flex-col items-center justify-center\" action={handleFormAction}\u003e\n      \u003cinput name=\"file\" type=\"file\" required className=\"rounded-lg border-2 border-dashed p-4\" /\u003e\n      \u003cbutton type=\"submit\" className=\"mt-4 rounded-lg bg-blue-500 p-2 text-white\"\u003e\n        Upload\n      \u003c/button\u003e\n    \u003c/form\u003e\n  );\n}\n```\n\n```ts\n// chunk-upload-action.ts\n\n'use server';\n\nimport type { FileHandle } from 'fs/promises';\nimport { open } from 'fs/promises';\nimport { join } from 'path';\n\nimport type { ChunkUploadHandler } from 'nextjs-chunk-upload-action';\n\nexport const chunkUploadAction: ChunkUploadHandler\u003c{ name: string }\u003e = async (\n  chunkFormData,\n  metadata\n) =\u003e {\n  const blob = chunkFormData.get('blob');\n  const offset = Number(chunkFormData.get('offset'));\n  const buffer = Buffer.from(await blob.arrayBuffer());\n  const filePath = join('./uploads', metadata.name);\n\n  let fileHandle: FileHandle | undefined;\n  try {\n    fileHandle = await open(filePath, offset === 0 ? 'w' : 'r+');\n    await fileHandle.write(buffer, 0, buffer.length, offset);\n  } finally {\n    await fileHandle?.close();\n  }\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa179346%2Fnextjs-chunk-upload-action-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa179346%2Fnextjs-chunk-upload-action-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa179346%2Fnextjs-chunk-upload-action-example/lists"}