-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ab2f4f
commit cbd50e0
Showing
12 changed files
with
221 additions
and
64 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { decode } from 'base64-arraybuffer'; | ||
import { ImagePickerAsset } from 'expo-image-picker'; | ||
import mime from 'mime'; | ||
import { BaseService } from './base.service'; | ||
|
||
class StorageService extends BaseService { | ||
async uploadAvatar(userUid: string, photo: ImagePickerAsset) { | ||
const mimeType = photo.mimeType; | ||
|
||
if (!mimeType) return; | ||
|
||
const ext = mime.getExtension(photo.mimeType!); | ||
const path = `${userUid}/avatar.${ext}`; | ||
|
||
const { data, error } = await this.client.storage | ||
.from('avatars') | ||
.upload(path, decode(photo.base64!), { | ||
upsert: true, | ||
contentType: mimeType | ||
}); | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
|
||
return data; | ||
} | ||
|
||
getAvatarURL(userUid: string): string { | ||
const { data } = this.client.storage.from('avatars').getPublicUrl(userUid); | ||
|
||
return data.publicUrl; | ||
} | ||
} | ||
|
||
export const storageService = new StorageService(); |
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
Oops, something went wrong.