I was trying to upload a file from Unity client (image) and receive this errors:
Code: Select all
SEVERE: Servlet.service() for servlet [sfs2x.ws.tomcat.upload.HttpUploadManager] in context with path [/BlueBox] threw exception [Upload Refused from: 103.119.50.79 Missing valid session token.] with root cause
javax.servlet.ServletException: Upload Refused from: 103.119.50.79 Missing valid session token.It was worked from the first time I created this feature on the game and suddenly throw this error.
From the logged in IP, and when the error thrown, I see a different IP between those two logs:
When Logged In, the IP is 103.119.50.21:60293
But when I tried to upload, it refused the IP 103.119.50.79
Code: Select all
05:44:17,262 INFO [SFSWorker:Ext:4] api.SFSApi - User login: { Zone: SlimeHaven }, ( User Name: Timmy_Guest_PC, Id: 0, Priv: 1, Sess: 103.119.50.21:60293 ) , Type: .Net
Jun 17, 2024 5:44:30 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [sfs2x.ws.tomcat.upload.HttpUploadManager] in context with path [/BlueBox] threw exception [Upload Refused from: 103.119.50.79 Missing valid session token.] with root cause
javax.servlet.ServletException: Upload Refused from: 103.119.50.79 Missing valid session token.and here is the uploadURI that I debug:
http://34.101.228.88:8080/BlueBox/SFS2XFileUpload?sessHashId=961948c428165ab6d1f4f1bde95458ab&__uid=666165156c143006f545f0f9&__pid=65c32bc4b1da1b094761b926
I can confirm that the sessHashId does match when the user logged in to the custom login handler.
I also already toggle on-off the "Enable X forward" in the Server Configuration but still receive this error
Here is the client code:
Code: Select all
IEnumerator IEUploadSlime(Texture2D texture, string uploadURL, Action OnSuccess = null, Action<string> OnFail = null)
{
this.texture = texture;
Debug.Log($"SFS SessionToken: {SmartfoxManager.Instance.sfs.SessionToken}");
Debug.Log($"Starting to upload. URL: {uploadURL}");
WWWForm postForm = new WWWForm();
postForm.AddBinaryData("theFile", texture.EncodeToPNG(), "full-transparent.png", "application/octet-stream");
WWW upload = new WWW(uploadURL, postForm);
yield return upload;
if (upload.error == null)
{
Debug.Log("Upload done :" + upload.text);
OnSuccess?.Invoke();
}
else
{
Debug.LogError("Error during upload: " + upload.error);
OnFail?.Invoke(upload.error);
}
}and here is the server code:
Code: Select all
public class UploadImageHandler extends BaseServerEventHandler {
static String Destination= "/home/timothyhermawan/SmartFoxServer_2X/SFS2X/www/ROOT/characters/";
@Override
public void handleServerEvent(ISFSEvent event) throws SFSException
{
System.out.println("========STARTING UPLOAD==============================");
User sender = (User) event.getParameter(SFSEventParam.USER);
List<UploadedFile> upFiles = (List<UploadedFile>) event.getParameter(SFSEventParam.UPLOAD_FILE_LIST);
Map<String, String> httpParams = (Map<String, String>) event.getParameter(SFSEventParam.UPLOAD_HTTP_PARAMS);
String uid = httpParams.get("__uid");
String pid = httpParams.get("__pid");
ClientSession session = GeneralUtility.CreateNewClientSession();
try
{
System.out.println("==============TRY=========================");
BasicSmartFoxResponse response = CharacterManager.Instance().SetNFTImageCaptured(session, pid, uid);
if(response.status != 1) return;
// System.out.println(response);
File theDir = [code][/code]new File(Destination);
if (!theDir.exists()){
theDir.mkdirs();
}
File tempFile = new File(upFiles.get(0).getTempFilePath());
File targetFile = new File(Destination + uid +"/" + upFiles.get(0).getOriginalName());
FileUtils.moveFile(tempFile, targetFile);
session.commitTransaction();
}
catch(IOException ioe)
{
System.out.println("==============CATCH=========================");
session.abortTransaction();
ioe.printStackTrace();
}
finally {
session.close();
}
}
}and here is the stack trace
Code: Select all
at sfs2x.ws.tomcat.upload.HttpUploadManager.validateSession(HttpUploadManager.java:229)
at sfs2x.ws.tomcat.upload.HttpUploadManager.doPost(HttpUploadManager.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at sfs2x.ws.tomcat.shared.WSUpgradeFilter.invoke(WSUpgradeFilter.java:75)
at org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:555)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)