Android Question Image File Upload/Download Compatible with B4a/B4i (without B4J)

swabygw

Active Member
Licensed User
Longtime User
What is the best method/library recommended for allowing users of my app to upload images (which will, then, be made viewable in the app)? Is there a method/library that I can, later, mirror in B4i and doesn't require using a B4J server?
 

KMatle

Expert
Licensed User
Longtime User
You don't want a server at all or a server without B4J?

No server = transmitting only local (network/BT) or via mail (see Erel's Email-Server example). But I do think that you think about that

Server but no B4J = via php & MySQL (okHttpUtils library)
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
Sorry, I should have mentioned more details. I'm using an IIS server to hold my database and images. My app uses XML web services to communicate with it. I'd like for users to be able to upload an image to the IIS server, I'll store it in some folder, and then have the app display the image when needed (either via a link, download, etc.).
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
My app uses XML web services to communicate with it

To call the web services use OkHttpUtils (I don't have an example for an IIS Server but I assume you know how to build the xml with headers - so just try the post method). The image should be converted to an byte array and then to a Base64 string and store it in a LONGTEXT in your database (which is the easy to handle).

Here I use Random Access File and StringUtils to do that (there are other methods to do that):

B4X:
Dim RAFin As RandomAccessFile
    Dim l As Int
   
    RAFin.Initialize(FilePath,FileName, False)
    l = File.Size(FilePath,FileName)
    Dim FileBuffer(l) As Byte
    RAFin.ReadBytes(FileBuffer,0,l,RAFin.CurrentPosition)
    RAFin.Close

    Dim B64String As String
    Dim su As StringUtils
    B64String=su.EncodeBase64(FileBuffer)   
    Log(B64String.Length)

and back
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
Actually, I don't want to store the file within the database. I just want to move the image file from the phone to a folder on the server.
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
After some more research, I see that there are a few options, actually (my mind was stuck on web services). So, my only question now is HttpUtils, HttpUtils2, OkHttp (or ImageViewer for downloading). It seems that they all have the ability to post an image file (or large file) and download a file. So...is it correct that OkHttp is the latest & greatest of these options for uploading, and ImageViewer is the best option for displaying?
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
Http, and httputils are the old libraries (I supose that maintained in forum for compatibility issues with old apps) and Okhttp an OKHttputils2 are the new libraries (the commands, methods and properties are the almost the same), so where you see Forum codes for http and httputils you can use it and only change the libraries references for the new ones (look at https://www.b4x.com/android/forum/threads/okhttp-replaces-the-http-library.54723/)

For image downloading, you can use an external lib (Picasso) or OKhttputils2 (imagedownloader example); for displaying the downloaded file, you've to use an imageview view (or modified alternatives as touchimage, etc..)
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
Thanks, I think that OkHttp and OkHttpUtils2 are what I need to do both the uploading and downloading jobs.
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
Right. Actually, ASP is my weapon of choice. :) I'll be thinking about folder location(s) and security next. On another note, consider this: to display an image, is it better (e.g., faster, better practice, etc.) to download the image and display it, or to display it by a link reference to a remote location (is this even possible)?
 
Upvote 0
Top