I’m trying to do a simple file upload using the MBS CURLSMBS plugin. Here’s the code:
curlObj = new CURLSMBS
curlObj.OptionPost = true
curlObj.OptionURL = "http://something/upload.php"
dim stream as BinaryStream = BinaryStream.Open(fileToUpload)
dim fileBuffer as string = stream.Read(stream.Length)
curlObj.FormAdd(curlObj.kFormCopyName, "file", curlObj.kFormBuffer, fileToUpload.Name, curlObj.kFormBufferPtr, _
fileBuffer, curlObj.kFormBufferLength, lenb(fileBuffer))
curlObj.OptionInFileSize = lenb(fileBuffer)
performError = curlObj.Perform
CURL returns no errors. But on the PHP side, there’s no form data. Both the $_REQUEST and the $_FILES globals are empty.
The PHP side works fine with a regular HTML form that does POST.
What am I doing wrong?
EDIT: this is Xojo 2016r4.1, MBS 16.4, Mac OS 10.11.6
Is there a reason you’re using CURLMBS instead of a HTTPSocket? Using a HTTPSocket would put the file data in the same way a HTML form would. I only ask because I’ve had success using HTTP Socket, and I’ve not needed to use CURLMBS for a file upload yet.
(Sorry I can’t be of more help)
Mostly because I thought CURL would handle the chunking and multipart form stuff for me. Is there an example somewhere of sending a file using multipart/form-data?
There doesn’t appear to be an example in the Example Projects.
I looked at one of my projects using HTTP Socket to upload via POST and I left myself this link in the comments:
@Tim Parnell : thanks for the link. I tried that code, and it works!
Ahh, the Miracle of Data Processing…
What doesn’t work exactly on the CURL code?
Does debug log show an error?
Hi Christian. Sorry, I deleted the project after I changed over to HTTPSocket, so I don’t know if there were any errors in the CURL debug log. There was nothing in the Xojo debug log. What was happening was that no POST data was getting through. On the PHP side, the $_REQUEST and the $_FILES globals were empty.
I may have a chance to revisit this later in the week. If I do, I’ll post my findings.