Users are discussing issues with uploading images via the Discourse API using various programming languages. Saurabh_Khandelwal and dhanya report receiving a 422 Unprocessable Entity error with the message undefined method 'tempfile' for #<String:...>, indicating a problem with the file parameter format. blake clarifies that the parameter should be files[] instead of file, referencing a Postman example. dhanya confirms the issue persists even when using files[] with binary data, resulting in a similar error. jwulf notes the discrepancy between the API documentation (which specifies application/json) and the actual required form-data format. CormacW43 confirms the issue remains unresolved, highlighting ongoing challenges in correctly formatting the upload request.
I’m trying to upload image using below discourse api through JAVA code: https://discourse.example.com/uploads.json
by passing json in Body:
{
“type” : “avatar”,
“user_id”: 1,
“synchronous”: true,
“file”: “Binary String”
}
Sending file as binary string. Getting response as given below. This is drupal
/uploads.jsonresulted in a422 Unprocessable Entityresponse: {"failed":"FAILED","message":"undefined methodtempfile’ for #\u003cArray:0x00007f0d5c784810\u003e"}