Android Question Multi-part json

barx

Well-Known Member
Licensed User
Longtime User
Can we create a muti-part Json object for sending. I want to send some files via json as well as other info. Looking at some articles on other sites, the best way to do it is to use multi part.

Is it just a matter of creating a list of lists or list of maps, etc. e.g.

B4X:
JSONList ->
    JSONMap1 ->
        DataField1 -> some data
        DataFiled2 -> some more data
    JSONMap2 ->
        File1 -> FileConvertedToByteArray
        ....
 

barx

Well-Known Member
Licensed User
Longtime User
Actually, maybe I am reading it all wrong, it maybe a multi part post with 1 part being the json. :confused:o_O
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
How big is the files?
If you are converting to byte array/base64 then maybe you do not even need to use a multipart upload.

10 images 2-3mb each.

I don't know if I am converting to byte array, I don't even know what a byte array is, lol. Just trying to figure best way to upload data and images to api.

another option I thought of was to send data as JSON and in the response send some ftp details, then app ftp to the server and upload file that way?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
10 images at 2-3 MB will be 30MB it will not be efficient with ByteArray/Base64. And may cause the app to crash.
The post above from Douglas contains useful information on multipart. Multipart request is just a regular request but with multiple items separated with a boundary. However the code linked still converts it to a byte array in the end before posting. (So I think its equivalent).
FTP doesnt sound bad as it solves some security issues too.
Otherwise maybe you can upload them one by one?
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
10 images at 2-3 MB will be 30MB it will not be efficient with ByteArray/Base64. And may cause the app to crash.
The post above from Douglas contains useful information on multipart. Multipart request is just a regular request but with multiple items separated with a boundary. However the code linked still converts it to a byte array in the end before posting. (So I think its equivalent).
FTP doesnt sound bad as it solves some security issues too.
Otherwise maybe you can upload them one by one?


There's another good option.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
10*2-3mb each imagewill possibly dont work with php on the destination-site. Most php-installations have a limit "max-post-size" and it is probably less than the needed size here.

I suggest to post each image (or two at once) in a single job
 
Upvote 0
Top