Page 1 of 1

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

Posted: 26 Oct 2024, 15:25
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!

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

Posted: 28 Oct 2024, 08:01
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

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

Posted: 28 Oct 2024, 10:34
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