Open maoapp opened 3 years ago
same problem here
Same issue here is my code
`import { Platform } from 'react-native'; import { azureblobfetch, initAzureBlob, } from 'react-native-azure-blob-storage-manager/azurblobstorage';
import crashlytics from '@react-native-firebase/crashlytics';
const accountName = 'p'; const containerName = 'l'; const accountKey = 'x'; initAzureBlob({ storageKey: accountKey, account: accountName, version: '2018-03-28', });
export const uploadMediaUtil = async ({ storagePath, kyc = false, media: { uri } }) => { try { console.log('Starting upload...'); // Log message
if (!uri || !storagePath) {
throw new Error('Missing required parameters: uri and storagePath');
}
// Handle platform-specific URI adjustments
const localUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri;
console.log('Local URI:', localUri); // Log message
// Construct the complete file name
const fileName = kyc ? `kyc-images/${storagePath}` : `${storagePath}`;
console.log('File Name:', fileName); // Log message
// Upload file to Azure Blob Storage
console.log('in tryyy');
const res = await azureblobfetch({
assest: { uri: localUri, filename: fileName },
container: containerName, //your countainer name,
filenameprefix: fileName, //add before the autogenrated file name,
type: 'Upload',
});
Upload.addListener('progress', res.uploadId, (data) => {
console.log(`Progress: ${data.progress}% `);
});
Upload.addListener('cancelled', res.uploadId, (data) => {
console.log(`Cancelled!`);
});
Upload.addListener('completed', res.uploadId, (data) => {
// data includes responseCode: number and responseBody: Object
console.log(data);
});
// const response = await EAzureBlobStorageFile.uploadFile({
// filePath: localUri,
// contentType: 'image/jpeg', // Assuming image/jpeg; adjust as needed
// fileName: fileName,
// });
console.log('Upload Response:', res); // Log message
if (res) {
console.log('Upload successful');
return `${storageUrl}/${containerName}/${fileName}`; // Return the uploaded image URL for further use
}
} catch (error) { console.error('Upload error:', error); crashlytics().recordError(error, 'Error in uploading image'); } };
`
I am having problems uploading pictures from IOS. The log message is the next :
I was debugging on Xcode and looks an error of invalid path
@"/Users/maoapp/Library/Developer/CoreSimulator/Devices/F2806DF4-D421-4552-B11E-84801C41DA9E/data/Containers/Data/Applicat ... BCBE.jpg is not a valid file:// url"
any tip to solve this?