Help with CURLSMBS and PUT

I’m trying to make a PUT using Curlsmbs but it seems it’s not my day :frowning:

The shell command working fine is:
curl -X PUT -H ‘Content-Type: multipart/form-data’ -F ‘mykey[image]=@/Users/myname/Documents/001.jpg’ -u mylogin:mypass https://apiweb.com/imagesapi.json

and my code is:

[code]Dim MyCurl as CURLSMBS = new CURLSMBS
MyCurl.OptionUsername = “mylogin”
MyCurl.OptionPassword = “mypass”
MyCurl.OptionURL = “https://apiweb.com/imagesapi.json
MyCurl.CollectDebugData = True
MyCurl.CollectOutputData = true
MyCurl.OptionUpload = True
MyCurl.OptionPut = True //just in case even if deprecated

//fPic is a FolderItem parameter
Dim ThisPic as picture = Picture.Open(fPic)
Dim buf as string =ThisPic.GetData(Picture.FormatJPEG,Picture.QualityLow) //change to high quality later

MyCurl.FormAdd(MyCurl.kFormCopyName,“mykey[image]”, MyCurl.kFormBufferPtr, buf, MyCurl.kFormBufferLength, lenb(buf))
// MyCurl.FormAdd(MyCurl.kFormCopyName,“mykey[image]”,MyCurl.kFormFile,fPic.NativePath) //also tried this way
MyCurl.FormFinish

Dim nReturn as integer = MyCurl.Perform[/code]

Using post with the same code works fine but now I need to use PUT and can’t get it working, no errors, just the image is not uploaded. I believe I’m not “translating” correctly the curl command to Curlsmbs.

Thanks for any help.

your transfer is doing a POST with PUT as custom request.

Form methods will switch to POST.

So please remove MyCurl.OptionUpload and MyCurl.OptionPut.
Use MyCurl.OptionPost = true and MyCurl.OptionCustomRequest = “PUT”.

That should do it.

Great, thanks Christian.

It is working now with the buffer method adding the file name like:
MyCurl.FormAdd(MyCurl.kFormCopyName,“mykey[image]”, MyCurl.kFormBuffer, sfilename, MyCurl.kFormBufferPtr, buf, MyCurl.kFormBufferLength, lenb(buf))

Please allow me to ask why the other method may not work:
MyCurl.FormAdd(MyCurl.kFormCopyName,“mykey[image]”,MyCurl.kFormFile,fPic.NativePath)

I’m interested in this to :slight_smile:

“Please allow me to ask why the other method may not work:
MyCurl.FormAdd(MyCurl.kFormCopyName,“mykey[image]”,MyCurl.kFormFile,fPic.NativePath)”

passing path may not work always, so I prefer passing by buffer.

Thanks