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