You can't use the liburl library on the iPhone, so you have to construct your own multipart forms. This seems to work in LiveCode desktop, but does not work on the iphone.
The killnewlines is required because otherwise, the file is messed up. the base64 encoder adds them in.
function killnewlines theText
repeat with i = the number of chars of theText down to 1
if char i of theText is linefeed then
delete char i of theText
end if
end repeat
return theText
end killnewlines
function post1
local theImage
export image "testimage" to theImage as JPEG
local theHeader, theBody
put "--__Part__" & crlf into theBody
put "content-Disposition: form-data; name=" & quote & "apiUserToken" & quote & crlf & crlf after theBody
put "2fAhc8tzTsF1BxVX2GnaJ8VfdvX1Nn" & crlf after theBody
put "--__Part__" & crlf after theBody
put "content-Disposition: form-data; name=" & quote & "sbxUserToken" & quote & crlf & crlf after theBody
put "2e763f13519f55f3dad49" & crlf after theBody
put "--__Part__" & crlf after theBody
put "content-Disposition: form-data; name=" & quote & "imageType" & quote & crlf & crlf after theBody
put "receipt" & crlf after theBody
put "--__Part__" & crlf after theBody
put "content-Disposition: form-data; name=" & quote & "inserterId" & quote & crlf & crlf after theBody
put "MyCompany" & crlf after theBody
put "--__Part__" & crlf after theBody
put "content-Disposition: form-data; name=" & quote & "images" & quote & ";filename=" & quote & "dummy.jpg" & quote & crlf after theBody
put "content-Type: application/octet-stream" & crlf after theBody
put "content-transfer-encoding: base64" & crlf & crlf after theBody
put killnewlines(base64encode(theImage)) & crlf after theBody
put "--__Part__--" after theBody
put "content-type: multipart/form-data; boundary=" & quote & "__Part__" & quote & crlf after theHeader
set the httpHeaders to theHeader
return theBody
end post1
localuploadShoeboxedURL
put "https://api.shoeboxed.com/v1/ws/api-upload.htm" into uploadShoeboxedURL
local theBody
put post1() into theBody
post theBody to URL uploadShoeboxedURL
HTTP multipart forms
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: HTTP multipart forms
or even quickerCode: Select all
function killnewlines theText repeat with i = the number of chars of theText down to 1 if char i of theText is linefeed then delete char i of theText end if end repeat return theText end killnewlines
Code: Select all
function killnewlines theText
replace LF with EMPTY in theText
return theText
end killnewlines
Re: HTTP multipart forms
Here is a an important update!!
The above code will not work on the iphone because of a header format issue.
I sent the code to LiveCode support and they kindly debugged it for me.
Here is the response they sent (I tried it and it works. Yaaay!!)
The reason for your issue is a slight bug in your code. The parsing of your header is done by the platform rather that LiveCode so as a result you see slight differences between desktop and iOS. iOS is strict to the letter of the law, whereas Desktop header parsing is a little more forgiving.
The following line of code is the culprit, and it particular to "crlf":
put "content-type: multipart/form-data; boundary=" & quote & "__Part__" & quote & crlf after theHeader
Should look like:
put "content-type: multipart/form-data; boundary=" & quote & "__Part__" & quote after theHeader
The above code will not work on the iphone because of a header format issue.
I sent the code to LiveCode support and they kindly debugged it for me.
Here is the response they sent (I tried it and it works. Yaaay!!)
The reason for your issue is a slight bug in your code. The parsing of your header is done by the platform rather that LiveCode so as a result you see slight differences between desktop and iOS. iOS is strict to the letter of the law, whereas Desktop header parsing is a little more forgiving.
The following line of code is the culprit, and it particular to "crlf":
put "content-type: multipart/form-data; boundary=" & quote & "__Part__" & quote & crlf after theHeader
Should look like:
put "content-type: multipart/form-data; boundary=" & quote & "__Part__" & quote after theHeader