Android Question downloading images from server and then uploading them to another server

Solution
Erel, I couldn't send images within 300 milliseconds using the previous method, so I changed the server to WebSocket. I managed to connect to it using the following approach. However, now my problem is that I don't know how to send an image through WebSocket.

zed

Active Member
Licensed User
Use OkHttpUtils2

 
Upvote 0

mhk1368

Member
Use OkHttpUtils2

thanks bro
I have done this task and downloaded the images, but I don't know how to send them. I have placed them under a link I used. Do you have any code that can help? I don't know how to send the received image.

 
Upvote 0

zed

Active Member
Licensed User
One way is to use WebView

There was a discussion about this.
 
Upvote 0

mhk1368

Member
One way is to use WebView

There was a discussion about this.
I have written the following code to send an image, and the code successfully returns "upload ok". However, on the server side, I'm not receiving anything. Can you help me troubleshoot the issue?

B4X:
Sub DownloadAndUploadImage(DownloadLink As String,Uploadlink As String, iv As ImageView)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(DownloadLink)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        UploadImage(j.GetBitmap,Uploadlink)
        iv.Bitmap = j.GetBitmap
    End If
    j.Release
End Sub

Sub UploadImage(Bitmap As Bitmap, UploadUrl As String)
    Dim jj As HttpJob
    jj.Initialize("", Me)
    Dim OutputStream As OutputStream
    OutputStream.InitializeToBytesArray(100)
    Bitmap.WriteToStream(OutputStream, 100, "JPEG")
    Dim ByteArray() As Byte = OutputStream.ToBytesArray
    jj.PostBytes(UploadUrl, ByteArray)
    Wait For (jj) JobDone(jj As HttpJob)
    If jj.Success Then
        Log("upload ok" )
    Else
        Log("upload error: " & jj.ErrorMessage)
    End If
    jj.Release
End Sub
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
for the upload you can use a postmultipart to your php file.

 
Upvote 0

mhk1368

Member
for the upload you can use a postmultipart to your php file.

I have seen this method before, but I don't know what values I should put in my code.


B4X:
    fd1.KeyName = "File"
    fd1.Dir = File.DirRootExternal
    fd1.FileName = file_upload
    fd1.ContentType = "text/plain"
 
Upvote 0

zed

Active Member
Licensed User
Do you have all necessary rights on the server.
I had this.
On my dev server everything was working fine and on the production server nothing was working.
I did not have the rights to connect remotely
 
Upvote 0

mhk1368

Member
Do you have all necessary rights on the server.
I had this.
On my dev server everything was working fine and on the production server nothing was working.
I did not have the rights to connect remotely
I can save the image and send it using the postmultipart method, but my problem is that I want to do this without saving the image on the device. In other words, what should I use instead of "fd1.Dir = File.DirRootExternal"?
 
Upvote 0

zed

Active Member
Licensed User
You can try with File.DirInternalCache.
Personally, I would make a copy in xui.defaultfolder and then when the operation is complete I delete the record.
 
Upvote 0

mhk1368

Member
Erel, I couldn't send images within 300 milliseconds using the previous method, so I changed the server to WebSocket. I managed to connect to it using the following approach. However, now my problem is that I don't know how to send an image through WebSocket.
 
Upvote 0
Solution

mhk1368

Member
Switching to WebSockets will not help.

How large are the images? What is your upload bandwidth?
Thank you, erel, for the time you have spent. I managed to solve this issue with the same websocket. It's possible that in my initial approach, I had a problem that prevented me from realizing it could be related to my B4A code or server-side settings and code. Nevertheless, my problem was resolved using the new approach. However, if it's possible to extend the first library and add image transmission to it, I think it could potentially solve the issues for other people as well.
 
Upvote 0

mhk1368

Member
You can send strings or bytes. Converting the image to bytes is simple and isn't something that should be implemented in the WebSocket library.
"I had also tried the same approach initially, but I couldn't achieve a transmission speed of less than 300 milliseconds."
upload speed:50MB
Downlown:150MB
 
Upvote 0
Top