We have a need to capture images in SF1 when network is offline, currently publishing actions are not supported but CRUD is supported, is it possible to create a lightning component that work offline and capture images? As per my research i see that lightning components are not supported offline, how would you approach this? Is a custom SDK app the only way for this? seeing if we can use SF1 since its something the users have been used to.
1 Answer
Have you looked into accessing local storage of the browser in SF1 .I would try the below code and see if that works .
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Device Capture</title>
</head>
<body>
<div>
<p>Capture a new image: <input type="file" accept="image/*" onchange="previewFile()" id="capture" capture="camera"><br>
<img id="curImage" height="200" size="" src=""><br>
<button onclick="storeImage()">Store Captured Image Offline</button>
<button onclick="loadImage()">Load Stored Image</button>
</div>
<script type="text/javascript">
function storeImage(){
var userImage = document.getElementById('capture');
if(userImage){
localStorage.setItem("imgData", document.getElementById('curImage').src);
}
}
function loadImage(){
var imageData = localStorage.getItem("imgData");
document.getElementById('curImage').src = imageData;
}
function previewFile(){
var preview = document.querySelector('img');
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
reader.onloadend = function(){
preview.src = reader.result;
}
if(file){
reader.readAsDataURL(file);
}
else {
preview.src = "";
}
}
</script>
</body>
</html>
-
i tried to run this and looks like there are compliance policy against using browser history, we might have to run this many approvals if this flow would be suggested, any way we can use lightning comp with SF1 to have offline capabilities? Commented Mar 7, 2017 at 6:03