need some help with libcurl.mod
BlitzMax Forums/Brucey's Modules/need some help with libcurl.mod
| ||
I've been trying to get some ftp uploading going with libcurl. But somehow I can't get it to work. Connecting to remote server works fine and I also manage to download a file from the server, thanks to the great examples. But when it comes to uploading I get stuck - no example to copy and paste from :-( I read through the help file half a dozen times and know that I have to create a readFunction(buffer:Byte Ptr, size:Int, data:Object)and then hook it up with curl.setReadCallback(myReadFunction, myData). But I can't figure out what needs to happen inside the readFunction()... Thanx for any help! |
| ||
Funnily enough, I've never actually tried uploading until now, so apologies for a lack of examples. Anyhoo, here's one which I've tested on my server and it seemed to work :-) I created a "helper" Type to look after the streaming, all in the name of good code re-use. Not sure if we need to close the stream afterwards, or if it is closed when the variable is GC'd... Here it is : |
| ||
Thanx very much Brucey, it works like a charm! I did put a close stream method into UploadHelper just to be on the save side. I've uploaded a file of 10MB and it finished without problems. But I will try now to to build in some functionality which will resume the download if it crashes... You should add the above sample to the libcurl docs. I really appreciate the fantastic support! |
| ||
Not sure if we need to close the stream afterwards, or if it is closed when the variable is GC'd... The stream in Uploadhelper should be closed. Otherwise theres is a lock on the uploaded file and it can't be deleted. Just in case someone else runs in this trap. |