Android Question Postfile OR Http Multipart Requests for Bitmaps?

lip

Active Member
Licensed User
Longtime User
I am using PostString in B4A to send JSON Strings to servers. After some issues with url encoding this is all working well.

I am now trying to upload bitmap files from the tablet (stored in File.DirRootExternal) to the servers. So far I have been using PostFile ie

Job1.PostFile("http://.....aspx",File.DirRootExternal,"file.bmp")

We can see something hitting the pages but struggling to interpret it at the server end. I am working with two different developers; one using vb.net and the other .asp. Both are having the same issues.

Should I forget PostFile and use the http.MultiPartPost...I have read a forum thread and it looks like I might get a bit more control like attaching Key/Value pairs to attach some information about the files, but it also looks far more complicated than Postfile?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It really depends on what the server expects. PostFile create a POST request with the file data as the request payload. If your server is configured to handle it then it is indeed very simple. You can use standard url parameters with PostFile.

If your server only accepts multipart requests then you need to follow this link: https://www.b4x.com/android/forum/threads/8411
 
Upvote 0

fixit30

Active Member
Licensed User
Longtime User
Hi Lip.

I upload files to my asp.net webserver using httputils PostBytes method.

On the Server Side the Byte Array can then be handled with the following code and either saved to a database or the file system as required.

B4X:
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim data() As Byte
        data = Request.BinaryRead(Request.TotalBytes)
        IO.File.WriteAllBytes("C:\PictureName.jpg", data)
    End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…