React Native - How to upload Audio files with spaces in their names - react-native

I have successfully been able to upload file when the filename is just one word, When there are spaces in the name, the file, I get error from server.
Example: 1.] '.../musics/Love.m4a' -> upload successfully
2] '.../musics/Love Thy Neighbor.m4a' -> upload failed
Any idea on how to handle this issue in React native will be highly appreciated.
I have been trying to upload an audio file in react-native but because of space in file name not being able to upload to server, I get below error from a server;
**file:** {uri: 'file:///Users/fathom-d004/Library/Developer/CoreSi…m.brandarmy.user1-Inbox/Love%20Thy%20Neighbor.m4a',
name: 'Love Thy Neighbor.m4a', type: 'audio/x-m4a'}
error: Error: ENOENT: no such file or directory, open '/Users/fathom-d004/Library/Developer/CoreSimulator/Devices/83619055-D45F-4FA9-85CC-A2009A599EA7/data/Containers/Data/Application/FE596B31-0385-4F77-B342-EF354F86FF1B/tmp/com.brandarmy.user1-Inbox/Love%2520Thy%2520Neighbor.m4a'

Used below simple solution;
I believe I've found the error. The issue was that the file I was uploading had a space in it, so we need to decode the URL first before uploading file to server, like:
var decodedURL = decodeURIComponent(file.uri);
const base64 = await fs.readFile(decodedURL, "base64");
Thanks...!

Related

Expo, how to save file from app directory to local directory

Im new to React Native and im using Expo to create an iOS and Android app. All I want to do is save a file that is stored in the application to the users device.
Using downloadAsync and shareAsync I can download from a remote url and save it but I can not download or just share a local file stored in in the apps directory.
Ive tried
await shareAsync('file://./manuals/mypdf.pdf');
await shareAsync('./manuals/mypdf.pdf');
await shareAsync(require('./manuals/mypdf.pdf'));
and I get the error
[Unhandled promise rejection: Error: You don't have access to provided file.] or the app just crashes
Use loadAsync to download asset data to a local file in the device's cache directory. After that the asset file is accessible like any other file.
const [{ localUri }] = await Asset.loadAsync(require('./manuals/mypdf.pdf'));

react native file system, fs, cannot find taken pictures

In my ReactNative application I am using "react-native-vision-camera": "^2.13.5" for taking pictures.
After the picture is taken and uploaded, I want to delete it from the device, but the RNFS (react-native-fs) cannot find the file by the given path on iOS and Android devicess:
I get the error
iOS ; [Error: ENOENT: no such file or directory, open
'/private/var/mobile/Containers/Data/Application/1BB2256A-ED83-407D-9C76-07431268779B/tmp/ReactNative/CE2FA429-76C8-4BD9-925A-BED09B0B77BB.jpeg']
Android ; [Error: File does not exist]
The path in Android is like: /data/user/0/packagename/cache/mrousavy2423256141715663083.jpg
const photo = await camera.current.takePhoto(); // camera: React.RefObject<Camera>
const task = storage().ref(<ref>).putFile(photo.path)
const result = await task.then(); // Firebase Storage can read and upload the photo
RNFS.stat(photo.path) // <-- Error: The file “CE2FA429-76C8-4BD9-925A-BED09B0B77BB.jpeg” couldn’t be opened because there is no such file.
RNFS.unlink(photo.path) // <-- [Error: ENOENT: no such file or directory, open '/private/var/mobile/Containers/Data/Application/1BB2256A-ED83-407D-9C76-07431268779B/tmp/ReactNative/CE2FA429-76C8-4BD9-925A-BED09B0B77BB.jpeg']
// Prepending file:// Does not work too
RNFS.unlink(`file://${photo.path}`)
RNFS.stat(`file://${photo.path}`)
Is it because of access permission that react-native-fs needs?
How does the firebase storage have access to the photo?
Is the path a real temp folder that gets cleared after the app is closed?
why react-native-vision-camera saves media there by default?
Do I really need to remove that media manually or does it get removed?
env:
"react-native": "0.68.2",
"react-native-fs": "^2.20.0",
"react-native-vision-camera": "^2.13.5",
physical device : iPhone 8 Plus with iOS 15.5
There is no need to delete the file as the photos are being stored in a temporary directory. It will be deleted when the app closes.
https://mrousavy.com/react-native-vision-camera/docs/api/interfaces/PhotoFile
Instead of calling RNFS.unlink(photo.path) try RNFS.unlink(photo.uri). The react-native-vision-camera API outputs a File object with a URI not a path.

Laravel download from cloud storage throws file not found error

I have a file stored in an s3 bucket. I can upload fine but when I try to download using the code below I get file not found exception thrown e.g.
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
The file "https://s3.us-west-2.amazonaws.com/mybucket/puppy.jpg" does not exist
When I navigate to the same url in a browser, the file downloads fine.
This is my code:
return response()->download(Storage::disk('s3')->url($file->path), $file->name);
Any ideas what I'm doing wrong?
This seems to work unless anyone know a more efficient technique:
return response()->streamDownload(function () use ($file) {
echo file_get_contents(Storage::disk('s3')->url($file->path));
} , $file->name);

Can download but file will not unzip as expected

I'm attempting to access the Geometadb database which first involves download of the SQL library. I did that and then I got the Geometadb library.
library(GEOmetadb)
Next I need the Geometadb file which is where things start to go wrong. I issue this command as seen exactly in the tutorial: https://bioconductor.riken.jp/packages/3.0/bioc/vignettes/GEOmetadb/inst/doc/GEOmetadb.html
if(!file.exists('GEOmetadb.sqlite')) getSQLiteFile()
It should proceed to not only download a .gz zip file but also unzip the file. It downloads it but never unzips it. Instead I get the following error.
trying URL 'http://dl.dropbox.com/u/51653511/GEOmetadb.sqlite.gz'
Error in download.file(url_geo, destfile = localfile, mode = "wb") :
cannot open URL 'http://dl.dropbox.com/u/51653511/GEOmetadb.sqlite.gz'
In addition: Warning message:
In url(url_geo_2, open = "rb") :
cannot open: HTTP status was '403 Forbidden'
Just not sure what's going on here. Considering these are just the early tutorial steps I'm probably missing something really obvious but I'm hoping someone can help me out. Thanks!

Backload -Errorcode-12 : Exception occured while storing the file

I have some issue in uploading file using JQueryFileUpload with Backload.
I have added settings in web.config to upload large file like 1 GB file allow.
When i try to upload zip file around 150MB it upload successfully but when i try to upload file around 200 MB it showing following exception.
errorcode:12
error: Exception occured while storing the file
Can you please help me to get the solution? Why i am getting above error?
I have one other question : can we use UNC path to save image outside of website folder? If yes then how we can use?
Thanks in advance.