From bc82af48128c5ab892d6f64cf6df4131159ba6ef Mon Sep 17 00:00:00 2001 From: thomasvo Date: Thu, 2 Oct 2025 15:06:35 -0700 Subject: [PATCH 01/28] update --- example/RNBGUExample/App.tsx | 82 +++++++---------------- example/RNBGUExample/android/build.gradle | 2 +- example/RNBGUExample/package.json | 2 +- example/RNBGUExample/yarn.lock | 8 +-- 4 files changed, 31 insertions(+), 63 deletions(-) diff --git a/example/RNBGUExample/App.tsx b/example/RNBGUExample/App.tsx index 135e6141..ce6f2027 100644 --- a/example/RNBGUExample/App.tsx +++ b/example/RNBGUExample/App.tsx @@ -24,9 +24,6 @@ import {Colors} from 'react-native/Libraries/NewAppScreen'; import Upload, {UploadOptions} from 'react-native-background-upload'; import {launchImageLibrary} from 'react-native-image-picker'; -import {createFormDataFile} from './utils/formdata'; - -const host = `http://${Platform.OS === 'ios' ? 'localhost' : '10.0.2.2'}:3000`; const App = () => { const [uploadId, setUploadId] = useState(); @@ -45,11 +42,26 @@ const App = () => { }); }, []); - const upload = ( - url: string, - path: string, - headers?: UploadOptions['headers'], - ) => { + const onPressUpload = async () => { + const url = 'https://httpbin.org/put/404'; + + const response = await launchImageLibrary({mediaType: 'photo'}); + + console.log('ImagePicker response: ', response); + const {didCancel, errorMessage, assets} = response; + if (didCancel) return; + + if (errorMessage) { + console.warn('ImagePicker error:', errorMessage); + return; + } + + const asset = assets?.[0]; + const path = Platform.OS === 'android' ? asset?.originalPath : asset?.uri; + if (!path) return Alert.alert('Invalid path'); + if (!asset?.type) return Alert.alert('Invalid file type'); + + // Video is stored locally on the device const uploadOpts: UploadOptions = { android: { notificationId: 'RNBGUExample', @@ -62,7 +74,9 @@ const App = () => { url, path, method: 'POST', - headers, + headers: { + 'Content-Type': asset.type || '', + }, }; Upload.startUpload(uploadOpts) @@ -80,26 +94,6 @@ const App = () => { }); }; - const getAsset = async () => { - const response = await launchImageLibrary({mediaType: 'photo'}); - console.log('ImagePicker response: ', response); - const {didCancel, errorMessage, assets} = response; - if (didCancel) return; - - if (errorMessage) { - console.warn('ImagePicker error:', errorMessage); - return; - } - - const asset = assets?.[0]; - const type = asset?.type; - const path = asset?.uri; - if (!path) return Alert.alert('Invalid file path'); - if (!type) return Alert.alert('Invalid file type'); - - return {path, type} as const; - }; - return ( <> @@ -109,33 +103,7 @@ const App = () => { style={styles.scrollView}> -