Skip to content

Commit ba958a7

Browse files
committed
fix: implement uploadBytes for storage modular sdk
1 parent 90ef814 commit ba958a7

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

packages/storage/lib/modular/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,28 @@ export function updateMetadata(storageRef, metadata) {
171171
* @param metadata - A Storage `SettableMetadata` instance to update. Optional.
172172
* @returns {Promise<TaskResult>}
173173
*/
174-
// eslint-disable-next-line
175174
export async function uploadBytes(storageRef, data, metadata) {
176-
throw new Error('`uploadBytes()` is not implemented');
175+
const task = uploadBytesResumable(storageRef, data, metadata);
176+
return new Promise((resolve, reject) => {
177+
task.on('state_changed', taskSnapshot => {
178+
switch (taskSnapshot.state) {
179+
case 'running':
180+
break;
181+
case 'paused':
182+
task.resume();
183+
break;
184+
case 'success':
185+
resolve({ ref: taskSnapshot.ref, metadata: taskSnapshot.metadata });
186+
break;
187+
case 'cancelled':
188+
case 'error':
189+
reject(taskSnapshot.error);
190+
break;
191+
default:
192+
throw new Error(`Unhandled task state in uploadBytes: ${taskSnapshot.state}`);
193+
}
194+
});
195+
});
177196
}
178197

179198
/**

0 commit comments

Comments
 (0)