Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
jwtea
- Posts: 66
- Joined: Fri Mar 23, 2018 2:01 am
Post
by jwtea » Mon Jun 04, 2018 2:21 am
Hello everybody,
In my mobile application, i got a card which is like a sign up card ~ In this card, user need to input details and when they press the sign up button , the details will be sent to my own website. In this card, there is a username , password and image data to be submit to my website.
The username and password can be submitted but image can't be submit anybody know how i can make the image data to be sent??
The button for user to input image
Code: Select all
on mousedown
create image "profilepicture"
put "*.jpg;*.gif;*.png" into types
if there is not an image "profilepicture" then
answer "please insert image"
end if
answer file "Select file" with type types
if it is empty then exit mousedown
put it into fn
if there is a file fn then
set the fileName of image "profilepicture" to fn
else
answer "please insert image"
end if
end mousedown
[The button to signup code]
Code: Select all
answer "Are you sure you want to signup?" with "No" and "Yes"
if it is "Yes" then
put field "username" into username
put field "password" into password
put image "profilepicture" into profilepicture
put "username="&username&" && password="&password&" && image="&profilepicture&"" into myData
post myData to URL "https://example.com/signup""
answer "Submited Successfully!"
go to card "logincard"
end if
end mouseup
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9660
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Mon Jun 04, 2018 3:16 am
Hi.
I am not sure about this, but isn't the "imageData" encoded in a universal format that is understood everywhere?
Craig Nerwman
-
bogs
- Posts: 5435
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Mon Jun 04, 2018 4:35 am
Erm, I would say that yes, imageData is the reference that (probably) is universal, *but* that doesn't necessarily imply it is ... easily transferrable, I guess. I recently went through a similar problem, one language I use created images suitable for storing and retrieving easily from a db, regardless of the original size of the image, I was easily able to display it again.
However, in re-writing that retrieval for Lc, it hasn't turned out as simple as I might have liked. I actually had to get the images out and saved in the other language, then stuff them back in with Lc.
-
mrcoollion
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Post
by mrcoollion » Mon Jun 04, 2018 5:52 am
I am not the expert here but maybe it helps to first use the following and then try to post it ?
Code: Select all
put base64encode(image "Imagename") into tBase64ImgData
Decode back into an image:
Code: Select all
put base64decode(tBase64ImgData) into image "Imagename" of card "Cardname"
I use it to get my images into my database and back.
Paul
-
jwtea
- Posts: 66
- Joined: Fri Mar 23, 2018 2:01 am
Post
by jwtea » Mon Jun 04, 2018 8:08 am
Hello all,
mrcoollion wrote: ↑Mon Jun 04, 2018 5:52 am
Code: Select all
put base64encode(image "Imagename") into tBase64ImgData
I had tried to use this code above but still failed ...
-
SparkOut
- Posts: 2852
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Mon Jun 04, 2018 8:15 am
It kind of depends on the server side what you need to do to send it.
Are you using LC Server to handle the data posted to it? Or php? Can we see some of the code used to receive and process the posted data.
Then we can see what kind of data formatting to do to match what it wants to receive.
-
jwtea
- Posts: 66
- Joined: Fri Mar 23, 2018 2:01 am
Post
by jwtea » Mon Jun 04, 2018 8:31 am
Hello SparkOut,
i'm actually using the Livecode POST action of HTTP to send the data to my web.
Code: Select all
put field "username" into username
put field "password" into password
put image "profilepicture" into profilepicture
put "username="&username&" && password="&password&" && image="&profilepicture&"" into myData
post myData to URL "https://example.com/signup""
answer it
The answer dialog box is empty but all data go thru except for the image ~ ~
SparkOut wrote: ↑Mon Jun 04, 2018 8:15 am
It kind of depends on the server side what you need to do to send it.
Are you using LC Server to handle the data posted to it? Or php? Can we see some of the code used to receive and process the posted data.
Then we can see what kind of data formatting to do to match what it wants to receive.
-
SparkOut
- Posts: 2852
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Mon Jun 04, 2018 1:50 pm
The point is, how does the SERVER handle the receipt and processing of the posted data?
-
jwtea
- Posts: 66
- Joined: Fri Mar 23, 2018 2:01 am
Post
by jwtea » Tue Jun 05, 2018 11:18 am
Hello all,
i can finally uploaded the image!!! Thanks for all of your help
Below is the button script ~
Code: Select all
on mousedown
answer "Are you sure you want to add?" with "No" and "Yes"
if it is "Yes" then answer "Confirm?" with "No" and "Yes"
if it is "Yes" then
put empty into tForm
put "https://example.com/signup" into tURL
put img "profilepicture" into tImage
put fld "username" into tUserName
put fld "password" into tPassword
put filename of img "profilepicture" into imgpath
put "<file>" & imgpath into tImage
put "image," & tImage into tArray[1]
put "username," & tUserName into tArray[2]
put "password," & tPassword into tArray[3]
if libUrlMultipartFormData(tForm, tArray) is not empty then
answer it ##error
else
set the httpHeaders to line 1 of tForm
post line 2 to -1 of tForm to url tURL
## check the result, etc., here
set the httpHeaders to empty
end if
end if
end mousedown