@@ -52,6 +52,58 @@ console.log(provider); // 'internal'
5252
5353---
5454
55+ ## Presigned URLs (Direct Client Uploads)
56+
57+ To allow frontend users to upload files directly without passing them through your server, use the presigned URL flow.
58+
59+ ### 1. requestUploadUrl (Server)
60+
61+ Generates a temporary upload URL. Requires your ** secret key** .
62+
63+ ``` typescript
64+ requestUploadUrl (filename : string , contentType : string , size : number ): Promise < { signedUrl : string , filePath : string }>
65+ ```
66+
67+ ### 2. uploadToPresignedUrl (Client)
68+
69+ A static helper to push the file to the generated URL from the frontend.
70+
71+ ``` typescript
72+ import { StorageModule } from ' @urbackend/sdk' ;
73+
74+ StorageModule .uploadToPresignedUrl (file : File | Blob | Buffer , signedUrl : string ): Promise < void >
75+ ```
76+
77+ ### 3. confirmUpload (Server)
78+
79+ Confirms the upload is complete and registers it in your storage quota.
80+
81+ ``` typescript
82+ confirmUpload (filePath : string , size : number ): Promise < UploadResponse >
83+ ```
84+
85+ ** Full Example (React + Node.js):**
86+
87+ ``` typescript
88+ // 1. Server: Generate link
89+ app .post (' /api/upload-link' , async (req , res ) => {
90+ const link = await urbackend .storage .requestUploadUrl (' cat.png' , ' image/png' , 500000 );
91+ res .json (link );
92+ });
93+
94+ // 2. Client (React): Upload directly
95+ const { signedUrl, filePath } = await fetch (' /api/upload-link' ).then (r => r .json ());
96+ await StorageModule .uploadToPresignedUrl (file , signedUrl );
97+
98+ // 3. Server: Confirm
99+ app .post (' /api/upload-confirm' , async (req , res ) => {
100+ const result = await urbackend .storage .confirmUpload (req .body .filePath , 500000 );
101+ res .json (result );
102+ });
103+ ```
104+
105+ ---
106+
55107## deleteFile
56108
57109Delete a previously uploaded file by its storage path.
0 commit comments