libUrlMultipartFormData on android error
Moderators: FourthWorld, heatherlaine, Klaus, 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).
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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- 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: 76
- 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 232 times
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: libUrlMultipartFormData on android error
Thank you! It works perfect
-
- Posts: 641
- Joined: Tue Jul 29, 2014 12:52 am
- Location: Brazil
Re: libUrlMultipartFormData on android error
Hi guys, this is really a great script.
I wonder if you have any example showing how to send some parameters (Keys=values) on top of the image itself.
I want to use the approach used here to send (in mobile) some metadata (like where the picture was taken, the date, etc...) together with the picture ...
Many thanks
I wonder if you have any example showing how to send some parameters (Keys=values) on top of the image itself.
I want to use the approach used here to send (in mobile) some metadata (like where the picture was taken, the date, etc...) together with the picture ...
Many thanks
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
-
- Posts: 641
- Joined: Tue Jul 29, 2014 12:52 am
- Location: Brazil
Re: libUrlMultipartFormData on android error
According to what I've found, and contrary to what is written in the dictionary, at least when the stand alone is built with 9.6.5 libUrlMultipartFormData works fine both on Android and iOS.
Anyone else has tested?
Anyone else has tested?
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question