playback
This commit is contained in:
@@ -1,13 +1,36 @@
|
||||
import { Platform } from "react-native";
|
||||
|
||||
import Compressor from "react-native-compressor";
|
||||
import firebase from "../config/firebase";
|
||||
|
||||
export function uploadFileToFirebase({ uri, path }) {
|
||||
export function uploadFileToFirebase({
|
||||
uri,
|
||||
path,
|
||||
shouldCompress = false,
|
||||
fileType = "",
|
||||
}) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let resultResize = { uri };
|
||||
let workingURI = uri;
|
||||
|
||||
const response = await fetch(resultResize.uri);
|
||||
// Optionally compress before upload
|
||||
try {
|
||||
if (shouldCompress && Platform.OS !== "web") {
|
||||
if (fileType === "VIDEO") {
|
||||
console.log("Compressing video...");
|
||||
workingURI = await Compressor.Video.compress(workingURI);
|
||||
} else if (fileType === "IMAGE") {
|
||||
// Basic image compression
|
||||
workingURI = await Compressor.Image.compress(workingURI, {
|
||||
compressionMethod: "auto",
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Compression failed, uploading original file", e?.message);
|
||||
workingURI = uri;
|
||||
}
|
||||
|
||||
const response = await fetch(workingURI);
|
||||
const blob = await response.blob();
|
||||
|
||||
const uploadTask = firebase.storage().ref(path).put(blob);
|
||||
|
||||
Reference in New Issue
Block a user