I've managed to upload files from a lc server script with a form, following this method :
http://lessons.runrev.com/s/lessons/m/4 ... ode-server
But now, I would like to upload a file from a desktop stack.
I guess it's necessary to build a special header before posting the file, to the lc script ? Someone could give me a clue ?
I tried this script, but without success :
http://forums.runrev.com/viewtopic.php?f=49&t=12954
Uploading file to LC Server from desktop app
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Uploading file to LC Server from desktop app
OK I found a solution, using libUrlMultipartFormData, thanks to :
http://www.lacscentre.com/liburl/liburl ... rtFormData
Here is the LiveCode script :
And now the LC Server script :
However I'm still looking for a working script using POST instead of libUrlMultipartFormData .
http://www.lacscentre.com/liburl/liburl ... rtFormData
Here is the LiveCode script :
Code: Select all
on mouseUp
put empty into tForm
put "http://www.my.com/yourcgi.lc" into tURL
answer file "Choose file: "
if it is empty then exit mouseUp
put "<file>" & it into tFile
--- note the "file". The same name must be used with the $_FILES var in LC server script
if libUrlMultipartFormData (tForm,"file", tFile) is not empty then
answer it
else
--- success
set the httpHeaders to line 1 of tForm
post line 2 to -1 of tForm to url tUrl
answer it
set the httpHeaders to empty
end if
end mouseUp
Code: Select all
<?lc
set the errormode to "inline"
if $_FILES["file"]["error"] then
put "ERROR"
else
put $_FILES["file"]["name"] into tFileName
put $_FILES["file"]["type"] into tFileType
put $_FILES["file"]["size"] into tFileSize
put $_FILES["file"]["filename"] into tFilePath
put tFilePath&" = "&"Your file '" & tFileName & "' was uploaded successfully. It is" && tFileSize && "bytes in size."
set the defaultFolder to "test/"
### if the file is a text file, use "file" instead of "binfile"
put URL ("binfile:" & tFilePath) into url ("binfile:"&tFileName )
put the result
end if
?>