Hello All,
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”
}
But in response I’m getting below result:
{
“failed”: “FAILED”,
“message”: “undefined method `tempfile’ for #String:0x000055fc2e0a01d8 ”
}
Where I’m doing wrong?
Please help me.
dhanya
(Dhanyamol K V)
September 22, 2020, 4:09pm
2
Experiancing the same problem. @Saurabh_Khandelwal if you are able to find a solution, Please reply me.
1 Like
blake
(Blake Erickson)
September 22, 2020, 4:23pm
3
The parameter for file
needs to be called files[]
. See this response for an example using Postman:
Okay I just verified that I got this to work. You just need to add the synchronous: true value to get the id.
[image]
now that we have the id: 17 we can then make one more request:
[image]
dhanya
(Dhanyamol K V)
September 22, 2020, 4:36pm
4
This is my sample data
Array
(
[type] => avatar
[user_id] => 3
[synchronous] => 1
[file ] => 1101000 1110100 1110100 1110000 1110011 111010 101111 101111 1101011 1101001 1111000 101101 1100100 1100101 1110110 101110 1100001 1110011 1110011 1111001 1110011 1110100 101101 1110101 1100011 101110 1100011 1101111 1101101 101111 1110011 1101001 1110100 1100101 1110011 101111 1100100 1100101 1100110 1100001 1110101 1101100 1110100 101111 1100110 1101001 1101100 1100101 1110011 101111 1110000 1101001 1100011 1110100 1110101 1110010 1100101 1110011 101111 110010 110000 110010 110000 101101 110000 110111 101111 1101011 1101001 1111000 1110100 1100101 1100001 1101101 1011111 1101001 1101101 1100111 110001 101110 1101010 1110000 1100111
)
Sending file as binary string. Getting response as given below. This is drupal
/uploads.jsonresulted in a
422 Unprocessable Entityresponse: {"failed":"FAILED","message":"undefined method
tempfile’ for #\u003cArray:0x00007f0d5c784810\u003e"}
Trying integration with Drupal to Discourse.
jwulf
(Josh Wulf)
December 8, 2020, 7:09am
5
Did you get this to work? I have been trying all manner of combinations with Node.js, and cannot get this to work.
I get a 422 Unprocessable Entity error.
In the Discourse docs , it says the content-type for the request is application/json
.
In this post , the Postman example is using form-data
, and when I watch the composer in the Discourse Web UI, it uses a multi-part post.
Anyone know how to do this via the API without using the Ruby client?
CormacW43
(Cormac W.)
August 28, 2024, 11:47am
6
This still doesn’t appear to be working.
This is the error I get when trying to upload an image, in binary that is.
Unprocessable Entity - {\"failed\":\"FAILED\",\"message\":\"undefined method `tempfile' for an instance of String\"}