Page 1 of 1

UPLOAD_HTTP_PARAMS Map Returns empty for Custom HTTP Parameters During File Upload

Posted: 18 Dec 2024, 15:52
by ciaoamigos
I am implementing file upload on the server using SmartFoxServer. I need to send additional parameters in the HTTP POST request and retrieve them server-side using the SFSEventParam.UPLOAD_HTTP_PARAMS map.

On the client side, I am sending the data like this:

Code: Select all

const formData = new FormData();
formData.append('sessHashId', sessHashId);
formData.append('fileName', fileName);
formData.append('__tipo', 'avatar'); // Custom parameter with double underscore



On the server side, my code to retrieve the additional parameters is as follows:

Code: Select all

@SuppressWarnings("unchecked")
Map<String, String> httpParams = (Map<String, String>) event.getParameter(SFSEventParam.UPLOAD_HTTP_PARAMS);
trace("HTTP Params: " + (httpParams != null ? httpParams.toString() : "null"));


However, the log outputs:

Code: Select all

HTTP Params:{}


This means that the additional parameters sent from the client are not being recognized server-side.

I would like to know how to correctly pass custom parameters with file uploads and have them properly recognized by SmartFoxServer.

Thanks in advance for any help!

Re: UPLOAD_HTTP_PARAMS Map Returns empty for Custom HTTP Parameters During File Upload

Posted: 18 Dec 2024, 17:02
by Lapo
Hi,
does the file upload work?
Can you show the complete JS code used for uploading?

Also what version of SFS2X are you using?

Thanks

Re: UPLOAD_HTTP_PARAMS Map Returns empty for Custom HTTP Parameters During File Upload

Posted: 18 Dec 2024, 17:30
by ciaoamigos
Hi,

I am using SmartFoxServer version 2.19.0 along with the BlueBox.war file that you provided.

The file upload itself works correctly, and the file is uploaded to the server without issues. However, the problem is that the extra parameters I am sending via FormData are not being detected in the UPLOAD_HTTP_PARAMS map on the server side.

Here is the complete JavaScript code I am using for the upload:

Code: Select all

const formData = new FormData();
formData.append('sessHashId', sessionToken);
formData.append('fileName', renamedFile);
formData.append('__tipo', 'avatar'); // Custom parameter with double underscore

I have double-checked the payload in the Google Chrome console, and it is correct. The parameter __tipo is present in the FormData and is being sent as part of the HTTP POST request.

Re: UPLOAD_HTTP_PARAMS Map Returns empty for Custom HTTP Parameters During File Upload

Posted: 19 Dec 2024, 07:44
by Lapo
Hi,
in the posted example where is the actual file to be uploaded?
I'd like to see the complete code. If you don't like the idea of posting it on a public forum, please send it via our support@ email box with a link to this topic.

Thanks