Working picture uploads. Videos failing due to URI.
This commit is contained in:
@@ -83,7 +83,7 @@ export function ImageBrowserScreen({
|
|||||||
const widgetSettings = useMemo(
|
const widgetSettings = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
getImageMetaData: false, // true might perform slower results but gives meta data and absolute path for ios users
|
getImageMetaData: false, // true might perform slower results but gives meta data and absolute path for ios users
|
||||||
initialLoad: 100,
|
initialLoad: 50,
|
||||||
assetsType: [MediaType.photo, MediaType.video],
|
assetsType: [MediaType.photo, MediaType.video],
|
||||||
minSelection: 1,
|
minSelection: 1,
|
||||||
// maxSelection: 3,
|
// maxSelection: 3,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Title, Button } from "react-native-paper";
|
|||||||
import { purgeStoredState } from "redux-persist";
|
import { purgeStoredState } from "redux-persist";
|
||||||
import SignOutButton from "../sign-out-button/sign-out-button.component";
|
import SignOutButton from "../sign-out-button/sign-out-button.component";
|
||||||
import * as Updates from "expo-updates";
|
import * as Updates from "expo-updates";
|
||||||
|
import * as Application from "expo-application";
|
||||||
|
|
||||||
export default function ScreenSettingsComponent() {
|
export default function ScreenSettingsComponent() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -21,7 +22,7 @@ export default function ScreenSettingsComponent() {
|
|||||||
>
|
>
|
||||||
<Title>
|
<Title>
|
||||||
{t("settings.labels.version", {
|
{t("settings.labels.version", {
|
||||||
number: `${Constants.expoConfig.version}-${Constants.expoConfig.extra.expover}`,
|
number: `${Constants.expoConfig.version}(${Application.nativeBuildVersion})`,
|
||||||
})}
|
})}
|
||||||
</Title>
|
</Title>
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export const handleUpload = async (ev, context) => {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
||||||
|
|
||||||
const newFile = await (
|
const newFile = await (
|
||||||
await fetch(imageData.localUri || imageData.uri)
|
await fetch(imageData.localUri || imageData.uri)
|
||||||
).blob();
|
).blob();
|
||||||
@@ -149,30 +150,33 @@ export const uploadToImgproxy = async (
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("file", {
|
|
||||||
uri: imageData.localUri,
|
|
||||||
type: fileType,
|
|
||||||
name: file.data.name,
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const s3UploadResponse = await cleanAxios.put(
|
await new Promise((resolve, reject) => {
|
||||||
preSignedUploadUrlToS3,
|
const xhr = new XMLHttpRequest();
|
||||||
file,
|
xhr.open("PUT", preSignedUploadUrlToS3);
|
||||||
options
|
xhr.setRequestHeader("Content-Type", fileType);
|
||||||
);
|
|
||||||
|
|
||||||
if (s3UploadResponse.status !== 200) {
|
xhr.upload.onprogress = (event) => {
|
||||||
console.log(
|
if (onProgress && event.lengthComputable) {
|
||||||
"Error uploading to cloudinary.",
|
onProgress({ percent: event.loaded / event.total, loaded: event.loaded });
|
||||||
s3UploadResponse.statusText,
|
}
|
||||||
s3UploadResponse
|
};
|
||||||
);
|
|
||||||
if (onError) onError(s3UploadResponse.statusText);
|
xhr.onload = () => {
|
||||||
return { success: false, error: s3UploadResponse.statusText };
|
if (xhr.status === 200) {
|
||||||
}
|
resolve();
|
||||||
//debugger;
|
} else {
|
||||||
|
reject(new Error(`Upload failed: ${xhr.statusText}`));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.onerror = () => {
|
||||||
|
reject(new Error("Network error"));
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send(file);
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error uploading to S3", error.message, error.stack);
|
console.log("Error uploading to S3", error.message, error.stack);
|
||||||
if (onError) onError(error.message);
|
if (onError) onError(error.message);
|
||||||
@@ -372,12 +376,16 @@ export function DetermineFileType(filetype) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function formatBytes(a, b = 2) {
|
export function formatBytes(a, b = 2) {
|
||||||
if (0 === a || !a) return "0 Bytes";
|
if (0 === a || !a || isNaN(a)) return "0 Bytes";
|
||||||
const c = 0 > b ? 0 : b,
|
const c = 0 > b ? 0 : b,
|
||||||
d = Math.floor(Math.log(a) / Math.log(1024));
|
d = Math.floor(Math.log(a) / Math.log(1024));
|
||||||
|
|
||||||
|
const parsedFloat = parseFloat((a / Math.pow(1024, d)).toFixed(c))
|
||||||
|
if (isNaN(parsedFloat)) {
|
||||||
|
return "0 Bytes";
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
parseFloat((a / Math.pow(1024, d)).toFixed(c)) +
|
parsedFloat +
|
||||||
" " +
|
" " +
|
||||||
["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]
|
["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user