XF 2.1 How to upload an attachment using the API?

aisller

Member
I read the manual, but it doesn't work yet


Does anyone have an example in PHP or Python ?
Thanks
 
I don't have example code per se, but it'd be helpful if you explained the problems you were running into (like any errors you received).

You need to get an attachment key for the scenario you're using it for (creating a thread, replying to a thread, etc), then upload a file (though you can upload the first attachment with the new key if you like). You'd then include the attachment key you got with the request to create or reply to the thread.

If you're using PHP, you may want to make sure that you use an HTTP client that supports file uploading as it changes how the request is structured. My tests have generally been using Guzzle (which is XF includes as a library).
 
Back
Top Bottom