Skip to content

Commit 4fc6eca

Browse files
Merge pull request #1366 from ItzNotABug/fix-upload-context-switches
Fix Upload Context Switches
2 parents 4023d7d + 8263e73 commit 4fc6eca

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/lib/stores/uploader.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { Models } from '@appwrite.io/console';
1+
import { Client, type Models, Storage } from '@appwrite.io/console';
22
import { writable } from 'svelte/store';
3-
import { sdk } from './sdk';
3+
import { getProjectId } from '$lib/helpers/project';
4+
import { getApiEndpoint } from '$lib/stores/sdk';
45

56
type UploaderFile = {
67
$id: string;
@@ -17,6 +18,15 @@ export type Uploader = {
1718
files: UploaderFile[];
1819
};
1920

21+
const temporaryStorage = () => {
22+
const clientProject = new Client()
23+
.setEndpoint(getApiEndpoint())
24+
.setMode('admin')
25+
.setProject(getProjectId());
26+
27+
return new Storage(clientProject);
28+
};
29+
2030
const createUploader = () => {
2131
const { subscribe, set, update } = writable<Uploader>({
2232
isOpen: false,
@@ -71,7 +81,7 @@ const createUploader = () => {
7181
n.files.unshift(newFile);
7282
return n;
7383
});
74-
const uploadedFile = await sdk.forProject.storage.createFile(
84+
const uploadedFile = await temporaryStorage().createFile(
7585
bucketId,
7686
id ?? 'unique()',
7787
file,

0 commit comments

Comments
 (0)