libUrlMultipartFormData on android error
Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
libUrlMultipartFormData on android error
Does the libUrlMultipartFormData support android?
I need to upload an image I captured on camera from the android device.
When I try to run it on android it doesn't work but when I do it on pc it does work.
Thank you
I need to upload an image I captured on camera from the android device.
When I try to run it on android it doesn't work but when I do it on pc it does work.
Thank you
Re: libUrlMultipartFormData on android error
Always check the dictionary!
Il will list all platforms where a command/function is supported or not!
For "libURLMultipartFormData" it lists: mac, windows, linux, html5
so you are out of luck.
But take a look at the resulting FORM in the IDE, should be not to hard to "rebuild" that one,
it is just text in the end.

Il will list all platforms where a command/function is supported or not!
For "libURLMultipartFormData" it lists: mac, windows, linux, html5
so you are out of luck.
But take a look at the resulting FORM in the IDE, should be not to hard to "rebuild" that one,
it is just text in the end.
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: libUrlMultipartFormData on android error
I did not mean to create a similar function, but to re-create the FORM that this command creates in the IDE.
What did you try so far?BigameOver wrote: ↑Fri Oct 02, 2020 8:27 amI tried to replace the parts with the binfile that doesn't work but it still doesn't work.
Please show us the script(s).
-
- VIP Livecode Opensource Backer
- Posts: 817
- Joined: Wed Nov 22, 2006 3:42 pm
- Location: France
- Contact:
Re: libUrlMultipartFormData on android error
Hi,BigameOver wrote: ↑Fri Oct 02, 2020 8:27 amHow do I build a similar function?take a look at the resulting FORM in the IDE, should be not to hard to "rebuild" that one,
I tried to replace the parts with the binfile that doesn't work but it still doesn't work.
following Klaus idea....
1) get this interesting stack from minu:
viewtopic.php?f=11&t=34705&p=196809#p196802
2) find in the stack script those lines:
Code: Select all
set the httpHeaders to line 1 of tForm
post line 2 to -1 of tForm to url tUrl
HTH,
Thierry
Thierry Douez
- Senior computer scientist
- Conseil, dévelopement et support en Français
https://sunny-tdz.com
https://sunny-tdz.com/livecode/externals
- Senior computer scientist
- Conseil, dévelopement et support en Français
https://sunny-tdz.com
https://sunny-tdz.com/livecode/externals
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: libUrlMultipartFormData on android error
I checked this out and it returns some things that I dont understand like boundary, etcThierry wrote: ↑Fri Oct 02, 2020 1:28 pmHi,BigameOver wrote: ↑Fri Oct 02, 2020 8:27 amHow do I build a similar function?take a look at the resulting FORM in the IDE, should be not to hard to "rebuild" that one,
I tried to replace the parts with the binfile that doesn't work but it still doesn't work.
following Klaus idea....
1) get this interesting stack from minu:
viewtopic.php?f=11&t=34705&p=196809#p196802
2) find in the stack script those lines:
3) set a breakpoint to the 2nd line and read the form text with the debugger.Code: Select all
set the httpHeaders to line 1 of tForm post line 2 to -1 of tForm to url tUrl
HTH,
Thierry
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: libUrlMultipartFormData on android error
Code: Select all
\
function libUrlMultipartFormDataAndroid @pFormData, pParam
local tNumParams,tNumParts,tBoundary,tKeys,tKey,tValue,tPart
local tFile,tNumFiles,tFilepath,tFilename,tSubBoundary
put the paramcount into tNumParams
if tNumParams < 1 then return "error Insufficient parameters"
put (tNumParams - 1) div 2 into tNumParts
put empty into pFormData ##ensure it is empty
answer "5.1"
##create initial boundary
put "__Part__" into tBoundary
put ulFormBoundary() after tBoundary
put "Content-type: multipart/form-data; boundary=" & quote & tBoundary & quote & return into pFormData
answer "5.12"
if tNumParams < 2 then
## do nothing for now, this will create empty shell for use with libUrlMultipartFormAddPart
else if tNumParams = 2 then ##treat as array
put keys(pParam) into tKeys
sort tKeys numeric
repeat for each line tKey in tKeys
put "--" & tBoundary & CRLF after pFormData
put "Content-Disposition: form-data; name=" & quote & item 1 of pParam[tKey] & quote after pFormData
put item 2 to -1 of pParam[tKey] into tValue
if char 1 to 6 of tValue = "<file>" then
put tValue into tFile
put empty into tValue
put char 7 to -1 of tFile into tFilepath
set the itemDel to "/"
put item -1 of tFilepath into tFilename
set the itemDel to comma
put ";" && "filename=" & quote & tFilename & quote after pFormData
put CRLF & "Content-Type: application/octet-stream" after pFormData
put tFile into tValue
answer "5.13"
if the result <> empty then
return "error" && the result
end if
end if
put CRLF & CRLF after pFormData
put tValue after pFormData
put CRLF after pFormData
end repeat
answer "5.2"
else if tNumParts > 0 then ##treat as key/value pairs
put 0 into tPart
repeat with i = 2 to tNumParams
if i mod 2 = 0 then ##stage 1 of part
add 1 to tPart
if tPart > tNumParts then exit repeat
put "--" & tBoundary & CRLF after pFormData
put "Content-Disposition: form-data; name=" & quote & param(i) & quote after pFormData
else
put param(i) into tValue
answer "5.5"
if char 1 to 6 of tValue = "<file>" then
put tValue into tFile
put empty into tValue
put char 7 to -1 of tFile into tFilepath
set the itemDel to "/"
put item -1 of tFilepath into tFilename
set the itemDel to comma
put ";" && "filename=" & quote & tFilename & quote after pFormData
put CRLF & "Content-Type: application/octet-stream" after pFormData
put tFile into tValue
if the result <> empty then
return "error" && the result
end if
end if
put CRLF & CRLF after pFormData
put tValue after pFormData
put CRLF after pFormData
end if
end repeat
end if
put "--" & tBoundary & "--" after pFormData ##end boundary
return empty
end libUrlMultipartFormDataAndroid
-
- VIP Livecode Opensource Backer
- Posts: 72
- Joined: Tue Mar 05, 2013 7:00 pm
- Location: Berlin
- Contact:
Re: libUrlMultipartFormData on android error
Here you will find how multipart form-urlencoded data is structured:
https://dev.to/getd/x-www-form-urlencod ... -mins-5hk6
i' ve attached a samplestack to upload images to ImgBB
without using libUrlMultipartFormData.
So it should work on mobile
1. Set HttpHeader
2. prepare post data
3. post data to url
https://dev.to/getd/x-www-form-urlencod ... -mins-5hk6
i' ve attached a samplestack to upload images to ImgBB
without using libUrlMultipartFormData.
So it should work on mobile
1. Set HttpHeader
Code: Select all
put "Content-type: multipart/form-data; " into theader
put "boundary=" & quote & "__Part__" & quote after theader
set the httpHeaders to theader
Code: Select all
function prepPostDatafromPath pimage
local tdata,tfilename,timageData
put url ("binfile:" & pimage) into timageData
set the itemdelimiter to slash
put last item of pimage into tfilename
put "--__Part__" & crlf into tdata
put "content-Disposition: form-data; name=" & quote & "image" & quote & ";filename=" & quote & tfilename & quote & crlf after tdata
put "content-Type: application/octet-stream" & crlf & crlf after tdata
put timageData & crlf after tdata
put "--__Part__--" after tdata
return tdata
end prepPostDatafromPath
Code: Select all
put prepPostDatafromPath(pLocalFilePath) into tpostData
post tpostData to url tUrl
- Attachments
-
- imgbbUpload_mobile.livecode.zip
- (4.18 KiB) Downloaded 39 times
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: libUrlMultipartFormData on android error
Thank you! It works perfect 
