blazerroadg / react-native-azure-blob-storage

This package help you to upload file and assets from react native project to your azure blob storage service
2 stars 0 forks source link

Error: NSInvalidArgumentException #6

Open maoapp opened 3 years ago

maoapp commented 3 years ago

I am having problems uploading pictures from IOS. The log message is the next :

at Object.promiseMethodWrapper [as startUpload] (index.bundle?platfor…rg.reactjs.na…:2599)
    at Object.startUpload (index.bundle?platfor….reactjs.na…:195875)

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?

IuriKintschev commented 2 years ago

same problem here

omkarKiranaClub commented 5 months ago

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'); } };

`