Issue
Developing screensaver channel and fetching images from AWS S3 bucket.
Environment
SDK
Answer
You can cache images by using CacheFS. In the same way that a file can be read from “pkg:/filepath/filename,” you can write and read from “cachefs:/filepath/filename."
CacheFS is available to all channels on our platform.
If you launch Channel A (which is using CacheFS) and later launch Channel B (which is also using CacheFS) on the same device, it is possible that Channel A's images are no longer cached due to CacheFS memory constraints.
Example of how to check if images is in CacheFS:
for each image in xml.image
cl=createobject("roSGNode","ContentNode")
cl.addField("url","string",false)
cl.addfield("title","string",false)
cl.addfield("author","string",false)
xfer.seturl(image.url.gettext())
'find last slash
txtstr=image.url.gettext()
txtstr=mid(txtstr,instr(txtstr,"//")+1)
while instr(txtstr,"/") > 0
txtstr=mid(txtstr,instr(txtstr,"/")+1)
end while
ttimer=createobject("rotimespan")
ttimer.mark()
if not fs.exists("cachefs:/"+txtstr) then
print "not in cache, get image"
xfer.seturl(image.url.gettext())
xfer.gettofile("cachefs:/"+txtstr)
print "transfer time";ttimer.totalmilliseconds()
else
print "found in cache!!!"
txtstr=image.url.gettext()
end if
print "transfer time";ttimer.totalmilliseconds()
cl.setfield("url",txtstr)
cl.setfield("title",image.title.getText())
cl.setfield("author",image.author.getText())
?image.url.gettext()
?image.author.gettext()
?image.title.gettext()
slidenode.appendChild(cl)
imgcount=imgcount+1
if imgcount > 20 then exit for
end for
Additional Resources
Architecture essentials > File system > Cachefs documentation
Is it possible to add roBitmap component to CacheFS?
If you are building a SceneGraph channel, we don't currently have a way to extract a bitmap and save it to a file.
However, if you are building a game using the 2D API, you can save a .png from an roBitmap by calling GetByteArray.
Comments
1 comment
i would like that someone explain how to read/write from cachefs, an example or something
Please sign in to leave a comment.