Get Static Path for an Asset in react native - ios

In my react native app i am showing several images in <Image> tags and i load those images from local folder.
<Image source={require('./src/images/image1.jpg')} />
I want to save image when the user tapped on it.
I can get which image user tapped and pass it to the function. But i put a single image path to it.
_onPressButton(imgName) {
CameraRoll.saveToCameraRoll( './src/images/image1.jpg' , 'photo').then(function(result) {
alert(result);
}).catch(function(error) {
alert(error);
});
}
But this gives me an error in iOS emulator saying it cant find the image in the path.
When i give as,
CameraRoll.saveToCameraRoll( 'https://i.imgur.com/JnrwMpZ.jpg' , 'photo')
It works.
But i want to save these files in my src/images folder.
How can i get a path of this image file OR get this done..?
I appreciate any help regarding this.
Thanks

Here is my solution with Expo, worked in android and should work on ios too
onSave = async () => {
const asset = Asset.fromModule(require('./src/images/image1.jpg'))
if (!asset.localUri) {
await asset.downloadAsync();
}
const uri = asset.localUri;
CameraRoll.saveToCameraRoll(uri, 'photo')
}

Related

Dropzonejs how to add/delete from server?

I know this is a very old issue but honestly I did not find a single complete piece of code for dropzonejs which is working as described.
I am trying to implement dropzonejs for file uploading. What I need is upload file to the server when it is dragged, and remove the file from the server when Remove file url is clicked.
I saw many solutions, for me, uploading just works fine. But when I try to implement the remove, I found no sample.
for the upload process, I configured my dropzone like below:
Dropzone.options.dropzoneForm = {
addRemoveLinks: true,
init: function() {
//upload process
}
};
It shows the addRemoveLink like "Remove file" just under the uploaded file.
I have seen someone to use another property like
Dropzone.options.dropzoneForm = {
addRemoveLinks: true,
removedFiles: function() {
//remove process
}
};
I am not sure how to implement this. Should I implement this like below? :
Dropzone.options.dropzoneForm = {
addRemoveLinks: true,
init: function(){
//upload process
}
removedFiles: function() {
//remove process
}
};
Please NB. I am expecting a full working example with server side upload and file delete.

Download files on iOS with React Native

I am building an app that lets the user download a PDF file when he clicks on a button.
I use the library react-native-fetch-blob for this purpose.
It works well on Android.
On iOS, the console log tells me the download has worked well, but:
I don't see anything happening on screen (on Android, there is a notification that tells me the download is complete)
I cannot find the file anywhere on the iPad. There is no "My files" folder or equivalent.
What is the right way to achieve what I want?
The solution thats worked for me in iOS was use RNFetchBlob.ios.openDocument function inside the then of fetch. This function open the file on the device file explorer where you have the option to download. Here is the code example:
downloadPDFiOS (uri) {
let uriSplitted = uri.split("/");
const fileName = uriSplitted.pop();
const dirs = RNFetchBlob.fs.dirs;
RNFetchBlob
.config({
path: dirs.DocumentDir + '/' + fileName,
fileCache: true,
})
.fetch('GET', uri, {
//some headers ..
})
.then((res) => {
RNFetchBlob.ios.openDocument(res.data);
})
.catch((e) => {
console.log('Error en el fetch: ', e);
})
}

How to save Highcharts image on server auomatically

I am using highcharts and Ruby on Rails to creating chart. I want to save graph as server automatically. Following code download image automatically on download folder with name as chart.png
events: {
load: function () {
var ch = this;
setTimeout(function(){
ch.exportChart();
});
}
}
I want to save grph as /asset/image folder with name today_Report.png
I don't think you can force user to save anything in folder you want to. That's about path, now about name for file, check this, example:
chart.exportChart({ "filename": "today_Report" });

ms-webview src property points to "local-stream:///" not "ms-appdata:///"

I have some code that loads an html file in a ms-webview within a Windows 8 store app (winJS) and I'm having an issue checking the URL src of the ms-webview. Basically, the user is able to navigate within the local html files, but I want to detect when they are back on the "home" screen...
var home = "ms-appdata://local/somefile.html";
myWebView.addEventListener("MSWebViewContentLoading", function(e) {
console.log(myWebView.src); // something like: ms-local-stream://[app_key]/somefile.html
console.log(e.uri); // same as above
if (myWebView.src === home) {
// nope...
}
});
myWebView.navigate(home);
As you can see above, the webview doesn't seem to give me a way to get the URL that I actually navigated to... Thoughts?
And yes, I could inspect the ms-local-stream URL path for the file I'm looking for, but surely there's a way to get the URL that was navigate to from the webview??

List files inside www folder in PhoneGap

Is it possible to list the files inside the www PhoneGap folder? And recursively?
I need it because I would like to preload all the images inside it.
The official documentation for working with files in phonegap can be rather hard to get started with.
Here's a working example of listing the files in a folder other than the root (in this case one called Downloads).
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory("Downloads", {
create: true
}, function(directory) {
var directoryReader = directory.createReader();
directoryReader.readEntries(function(entries) {
var i;
for (i=0; i<entries.length; i++) {
log(entries[i].name);
}
}, function (error) {
alert(error.code);
});
} );
}, function(error) {
alert("can't even get the file system: " + error.code);
});
Note this will give you a directory in the writable area (Documents on iOS, sdcard on Android, so may not help that much).
here's a PhoneGap app that does just that, even if written for BlackBerry, the jscript/html code is the same and should work in your iOS app as well.
Hope this helps

Resources