Android Question FTP upload of an existing image [SOLVED]

ThePuiu

Active Member
Licensed User
Longtime User
I would like the user to be able to choose an existing image and upload it to the FTP server. I tried to use the following code to identify the image:
B4X:
cc.Initialize("CC")
cc.Show("image/*", "Select image")
Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
    Dim sf As Object = ftp.UploadFile( Dir, FileName, False, FileName)
    .........
End If
The code returns as values:
Dir = ContentDir
FileName = content://com.android.providers.media.documents/document/image%3A5216

and obviously the upload is not performed. What should I do so that the user can upload images from anywhere on his device (internal or SD Card)?

I tried to upload an image from a known location and the code works.
B4X:
Dim sf As Object = ftp.UploadFile( File.DirRootExternal, "test.jpg", False, "test.jpg")

Thank you!
 

JohnC

Expert
Licensed User
Longtime User
The problem is that the selected image is being returned as a URI and not as a separate directory and filename.

You would first need to copy the file from the URI returned from the "FileName" property to a local directory like File.DirInternal.

Then you can use that local copy as the source to upload via FTP.

However you may very well run into the problem of not being able to determine the filename from the URI as described here:


So, when you do the copy from the URI to a local directory, you may need to make up a name for the file.
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
I read some similar posts in the forum and I came across your question a few moments ago! Thanks for the answer, I will apply this method although it seems a little strange!
 
Upvote 0

manuaaa

Member
Licensed User
Longtime User
can
The problem is that the selected image is being returned as a URI and not as a separate directory and filename.

You would first need to copy the file from the URI returned from the "FileName" property to a local directory like File.DirInternal.

Then you can use that local copy as the source to upload via FTP.

However you may very well run into the problem of not being able to determine the filename from the URI as described here:


So, when you do the copy from the URI to a local directory, you may need to make up a name for the file.

can you please provide one sample, Thanks & regards
 
Upvote 0
Top