UPLOAD_HTTP_PARAMS Map Returns empty for Custom HTTP Parameters During File Upload

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
ciaoamigos
Posts: 70
Joined: 05 Sep 2021, 16:57

UPLOAD_HTTP_PARAMS Map Returns empty for Custom HTTP Parameters During File Upload

Post 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!
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

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

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
ciaoamigos
Posts: 70
Joined: 05 Sep 2021, 16:57

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

Post 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.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

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

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply