Skip to content

Commit

Permalink
feat: add metadata field
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Nov 28, 2023
1 parent 965d329 commit 28eb3e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 126 deletions.
124 changes: 0 additions & 124 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ class HttpRequest {
}

export const createPresignedUrl = async (
{ bucketName, apiUrl, file, token }: { bucketName: string; apiUrl?: string; file: File; token: string },
{ bucketName, apiUrl, file, token, metadata }: {
bucketName: string
apiUrl?: string
file: File
token: string
metadata?: Record<string, string>
},
) => {
await createBucket({ bucketName, apiUrl, token })
const url = parseUrl(`https://${apiUrl ?? FILEBASE_API_URL}/${bucketName}/${file.name}`)
Expand All @@ -90,8 +96,10 @@ export const createPresignedUrl = async (
sha256: HashImpl.bind(null, 'sha256') as unknown as ChecksumConstructor,
})

const headers = metadata ? Object.fromEntries(Object.entries(metadata).map(([k, v]) => [`x-amz-meta-${k}`, v])) : {}

const signedUrlObject = await presigner.presign(
new HttpRequest({ ...url, method: 'PUT', headers: {} }),
new HttpRequest({ ...url, method: 'PUT', headers }),
{ expiresIn: 3600 },
)
return formatUrl(signedUrlObject)
Expand Down

0 comments on commit 28eb3e9

Please sign in to comment.