I want to send image to websocket by javascript as MultipartFile
My js code
if (stompClient && stompClient.connected) {
const imageData = document.querySelector('input[type="file"]').files;
const formData = new FormData();
formData.append("file", imageData[0]);
if (imageData) {
const message = {
'userId': userId,
'token': token,
'messageType': 'PHOTO',
'chatId': chatId,
'file': formData // Use FormData for file upload
};
console.log('Sending message: ', message);
stompClient.send("/app/messages/" + chatId, {}, JSON.stringify(message));
}
}
Logi
`>>> SEND
destination:/app/messages/5
content-length:111
{"userId":"4","token":"576e6e38864f4b3da266ca42baf32218617302474","messageType":"PHOTO","chatId":"5","file":{}}�`
`Sending message:
Object { userId: "4", token: "576e6e38864f4b3da266ca42baf32218617302474", messageType: "PHOTO", chatId: "5", file: File }
file: File { name: "ziutek2.png", lastModified: 1716816552352, size: 20691, … }`
I don’t know how to fix that problem
New contributor
xMaster is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.