Android Question Download image from web than we didn't the filename

nickysuwandi

Member
Licensed User
Longtime User
Dear All

I have create Restfull API to send image when users request from API link.

Have trouble to coding in B4A to receive this image and save to phone. It's there anyone can share some code and tutorial to do that?
this the example API Link



Thanks

Nicky
 

Alexander Stolte

Expert
Licensed User
Longtime User
 
Upvote 0

nickysuwandi

Member
Licensed User
Longtime User
thanks Alexander, i have read the tutorial before, still understand how to catch the image without file name.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
all downloaded resources are returned as bytes.
images - with or without a name - are returned as a stream of bytes.
if you know the resource is an image, you capture it as a bitmap:

dim downloadedbitmap as bitmap = httpjob.getbitmap

once you have the bitmap, you are free to assign any name you want to it (even if it already has a name)
you can save it as a .jpg or .png:

Dim out As OutputStream
out = File.OpenOutput(location, fname, False)
downloadedbitmap.WriteToStream(out, quality, "JPEG")
out.Close


if users are able to select whatever resource they want to download, then you
may want to check if the url has a name or not. if there is no name, you simply
give the resource whatever name you want (preferably a unique name unless
you want to allow users to overwrite an image they might already have with that
name).
 
Upvote 0

nickysuwandi

Member
Licensed User
Longtime User
Thanks drfottjr, i will try it
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Are you using B4J server to create the REST API?
Here is an example.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…