Sending an HTTP JSON Response after File Upload with FILE_UPLOAD Event in SmartFoxServer

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

Sending an HTTP JSON Response after File Upload with FILE_UPLOAD Event in SmartFoxServer

Post by ciaoamigos »

Hi everyone,

I’m developing an extension in SmartFoxServer 2X to handle file uploads using the FILE_UPLOAD event. The goal is to return a JSON response to the client that includes the upload status (e.g., success or failure) and some additional information, like the name of the uploaded file, directly after the operation is completed.

Current Configuration
-Extension (UploadTestExtension):
I’ve set up UploadTestExtension to handle the FILE_UPLOAD event using a handler, UploadTestHandler, where the upload logic occurs. At the end of the upload, I would like to send back a JSON response.

-Problem:
I’m struggling to find a way to send a direct HTTP JSON response to the client once the file upload completes. Since SmartFoxServer natively handles only extension messages, I'm finding it difficult to provide the client with a JSON structure confirming the success of the operation.

-Question
Is there a way to directly send an HTTP JSON response to the client from SmartFoxServer once a FILE_UPLOAD event completes? Any guidance or examples on how to set up this JSON response so the client can interpret it would be greatly appreciated.

Thanks very much for any help!
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending an HTTP JSON Response after File Upload with FILE_UPLOAD Event in SmartFoxServer

Post by Lapo »

Hi,
there's no easy way to do that because you would need to create your own servlet handling the upload and providing a custom response to the client.
Why not just sending an Extension response with the required data instead? It seems the solution to your problem.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
ciaoamigos
Posts: 70
Joined: 05 Sep 2021, 16:57

Re: Sending an HTTP JSON Response after File Upload with FILE_UPLOAD Event in SmartFoxServer

Post by ciaoamigos »

Thanks for the suggestion, I appreciate the advice. However, the context is different: if I make a POST request, I expect a response from the call, both to catch errors and to confirm if everything went wel
Post Reply