Page 1 of 2
Upload Image via FTP
Posted: Sat Feb 08, 2014 12:31 am
by cbarnhart
I have read numerous post and tied numerous suggestion but I an really stuck. I have a image on screen that I wuold like to FTP to my server when a button is clicks. Works on desktop but does not work on Android tablet. this is what I have
Code: Select all
export image "Image" to file specialFolderPath("engine") &slash&"newimage.png" as PNG
put specialFolderPath("engine") & slash&"newimage.png" into tFileForUpload
put url("binfile:"&tFileForUpload) into url ("ftp://"&FTPUSER&":"&FTPPASS&"@"&FTPHOST&"/consignapp/newimage.png")
any suggestions?
Re: Upload Image via FTP
Posted: Sat Feb 08, 2014 12:37 am
by Simon
Hi cbarnhart,
You should be using specialFolderPath("documents") not engine.
The engine folder cannot be written to.
Simon
Edit:
Code: Select all
put url ("binfile:" & specialFolderPath("documents") & "/newimage.png") into tImageUpload
put tImageUpload into url ("ftp://"&FTPUSER&":"&FTPPASS&"@"&FTPHOST&"/consignapp/newimage.png")
not sure if it can write folders so make sure the folder exists before the upload.
Re: Upload Image via FTP
Posted: Sat Feb 08, 2014 1:23 am
by cbarnhart
Thank you Simon. I updated my code so now it reads
Code: Select all
export image "Image" to file specialFolderPath("documents")& "/newimage.png" as PNG
put url ("binfile:" & specialFolderPath("documents") & "/newimage.png") into tImageUpload
put tImageUpload into url ("ftp://"&FTPUSER&":"&FTPPASS&"@"&FTPHOST&"/consignapp/newimage.png")
if the result is not empty then
answer "url put failed:" && the result
else
answer "success!"
end if
Still no go. I know I have the FTP info correct because it does work on the desktop. But on the Android tablet I am getting
'url failed java.io.ioexception'
any other suggestions
Re: Upload Image via FTP
Posted: Sat Feb 08, 2014 1:40 am
by cbarnhart
also it does create the file on the FTP server but the file never gets past "0" in size
Re: Upload Image via FTP
Posted: Sat Feb 08, 2014 2:27 am
by FourthWorld
I think they key here is Android. AFAIK libURL, and hence, FTP, isn't available in LiveCode on Android. Probably just as well, since FTP is notoriously insecure (FTP passwords are sent in plain text).
If you can use LiveCode Server or PHP on the server with a script to accept the image upload, you could send it from the client app using a POST command over HTTP/HTTPS.
Re: Upload Image via FTP
Posted: Sat Feb 08, 2014 6:03 pm
by cbarnhart
Thank you Fourth
Not the answer I wanted but at least I know what my options might be
Re: Upload Image via FTP
Posted: Sun Feb 09, 2014 12:39 am
by FourthWorld
You could write one in LC easily enough (I have a script for that lying around here somewhere), but there are so many well-documented PHP scripts for it that it's probably easiest to just drop in one of those:
https://www.google.com/search?q=php%20f ... d%20script
Re: Upload Image via FTP
Posted: Sun Feb 09, 2014 4:22 am
by Simon
Hi Richard,
I have gone round and round with php cgi 'n stuff but still can't figure out how to post from a stack.
OK let me show you how little I know.
I do have a working upload php script and html form on my server but that requires the "submit" button (or does it?).
ENCTYPE="multipart/form-data" does that say I have to use libURLMultipartFormData? Because that isn't part of mobile.
I have liveCode server... Can all this be written in liveCode? Still I wouldn't know where to start.
I haven't paid Mark yet for his method because of the file size restriction. Maybe the only person who knows how?
I'm looking for uploading binary as well as text files.
Thanks for any insights.
Simon
ps Don't know why I forgot that mobile has this problem, I shouldn't have replied to the OP.

Re: Upload Image via FTP
Posted: Sun Feb 09, 2014 4:34 am
by Dixie
Simon wrote:
I haven't paid Mark yet for his method because of the file size restriction.
And there was me thinking that the idea of a forum such as this was to share the knowledge, the tips and the tricks.. not charge a 'dollar' for a few lines of script ...
Ah well... silly me
Re: Upload Image via FTP
Posted: Mon Feb 10, 2014 1:10 pm
by LCNeil
Hi Everyone, Uploading a file via "PUT URL" should work on Android devices, however, when writing an example script, I came across a bug that you might be experiencing.
The following script works perfectly on iOS but fails on Android with the mentioned Java.io.ioexception error.
Code: Select all
put "test@test.on-rev.com" into sUsername
put "Aasecurepassword" into sPassword
put "ftp.test.on-rev.com" into sHost
put "test" into sName
mobilePickPhoto "library"
if it is "cancel" then
exit mouseUp
end if
put urlEncode(sHost) into sHost
put urlEncode(sUsername) into sUsername
put urlEncode(sPassword) into sPassword
put urlEncode(sName) into sName
export the last image to file (specialFolderPath("documents") &slash&"newimage.png") as PNG
put url("binfile:" & specialFolderPath("documents") & "/newimage.png") into tImageUpload
--answer ("ftp://"&sUsername&":"&sPassword&"@"&sHost & slash &sName&".png")
put tImageUpload into url ("ftp://"&sUsername&":"&sPassword&"@"&sHost & slash &sName&".png")
if the result <>empty then
answer "url put failed:" && the result
else
answer "success!"
end if
I have changes the username/password above to generic values
With this error occurring, I spoke to the dev team and it would seem that usernames with "@" in them fail on Android (and possibly other non alphanumeric characters). I then tried my script with a simple alphanumeric username and pass and the upload was successful.
We are now aware of this issue and have created a bug report on it with out Quality Control Team.
http://quality.runrev.com/show_bug.cgi?id=11779
Hopefully we will have a quick resolution for this.
Kind Regards,
Neil Roger
--
RunRev Support Team ~
http://www.runrev.com
-
Re: Upload Image via FTP
Posted: Mon Feb 10, 2014 8:24 pm
by Simon
Hi Neil,
Thanks for this.
Why doesn't URLEncoding work on the username with @?
Simon
Re: Upload Image via FTP
Posted: Tue Feb 11, 2014 10:09 am
by LCNeil
Hi Simon,
I believe that even though it is being urlEncoded, the bug mentioned above means the current implementation of URL on Android still results in a failed FTP connection with the encoded data. Its something that we will hopefully be able to track down relatively quickly as the same script works fine on iOS.
Kind Regards,
Neil Roger
--
RunRev Support Team ~
http://www.runrev.com
--
Re: Upload Image via FTP
Posted: Tue Feb 11, 2014 11:11 am
by Simon
Hi Neil,
Again, thanks for your support.
As it is, I see no way of getting info off Android except for the message body of an email. I hope you know that attachments don't work on Android.
While I'm very happy about ftp being work on, as is clear form Richards admant writings ftp is no way to transfer info. I'm not asking about sftp but will an "https put" be available?
Thanks,
Simon
Re: Upload Image via FTP
Posted: Tue Feb 11, 2014 11:41 am
by LCNeil
Hi Simon,
The Android mail attachment bug is marked as “Awaiting Build”. This means that it should be fixed in the next releases of LiveCode.
As part of our roadmap, we are working on a new cross platform network layer and this will hopefully implement some of the discussed above-
http://livecode.com/community/roadmap/
In regards to using https, if you have a valid SSL certificate setup on your web hosting and are using the LiveCode server method suggested above, then you should be able to pass data without any issue. The following is a lesson on how to pass data to LiveCode server-
http://lessons.runrev.com/s/lessons/m/4 ... r-scripts-
More info on LiveCode server can be found here-
http://lessons.runrev.com/s/lessons/m/4070
and
http://livecode.com/developers/guides/server/
Kind Regards,
Neil Roger
--
RunRev Support Team ~
http://www.runrev.com
--
Re: Upload Image via FTP
Posted: Tue Feb 11, 2014 9:53 pm
by Simon
Hi Neil,
The lesson for uploading a file contains;
<form enctype="multipart/form-data" action="file_upload_example.lc" method="POST">
Which I think means using libURLMultipartFormData which is not part of mobile.
Is that correct?
Can I stop beating my head against the wall and just admit there is no way of uploading a file to a server via Android?
Simon