-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix presign file upload for user avatar
- Loading branch information
Showing
5 changed files
with
42 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { client } from "$lib/server/deepwell" | ||
|
||
export async function getFileByHash( | ||
/** Either a Uint8Array or a hex string */ | ||
fileHash: Uint8Array | string | ||
): Promise<Blob> { | ||
let res = await client.request( | ||
"blob_get", | ||
typeof fileHash === "string" ? fileHash : Buffer.from(fileHash).toString("hex") | ||
) | ||
|
||
return new Blob([new Uint8Array(res.data)], { type: res.mime }) | ||
} | ||
|
||
export async function startBlobUpload(userId: number, blobSize: number) { | ||
return await client.request("blob_upload", { | ||
user_id: userId, | ||
blob_size: blobSize | ||
}) | ||
} | ||
|
||
export async function cancelBlobUpload(userId: number, pendingBlobId: string) { | ||
return await client.request("blob_cancel", { | ||
user_id: userId, | ||
pending_blob_id: pendingBlobId | ||
}) | ||
} | ||
|
||
export async function uploadToPresignUrl(url: string, file: File) { | ||
return await fetch(url, { | ||
method: "PUT", | ||
body: file | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters