Android Question HttpServer Upload file problem

RobertoS

Member
Licensed User
Longtime User
Hi,
I am creating an app to act as a server to receive images (the images will then be sent by a windows application written in vb.net).
I'm using the HttpServerExample to do some testing, but I've noticed that if I try to upload a picture by connecting via browser it gives me this error:

B4X:
A Non sicuro | 172.30.86.106:5555/upload/storage%2Femulated%2F0%2FDownload%2F
HTTP ERROR: 500
Problem accessing /upload/storage%2Femulated%2F0%2FDownload%2F. Reason:
java. lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.close()' on a null object reference
Powered by Jetty://

Screenshot 2023-10-12 115300.png

and the B4A log gives me this other error

B4X:
2023-10-12 11:55:39.184:WARN::/upload/storage%2Femulated%2F0%2FDownload%2F
java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.close()' on a null object reference
    at anywheresoftware.b4a.objects.Servlet.doPost(Servlet.java:68)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
    at org.eclipse.jetty.server.Server.handle(Server.java:346)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1065)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:823)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
    at org.eclipse.jetty.server.nio.BlockingChannelConnector$BlockingChannelEndPoint.run(BlockingChannelConnector.java:289)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$1.run(QueuedThreadPool.java:529)
    at java.lang.Thread.run(Thread.java:1012)
Caused by:
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.close()' on a null object reference
    at org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:329)
    at anywheresoftware.b4a.objects.Servlet.doPost(Servlet.java:66)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
    at org.eclipse.jetty.server.Server.handle(Server.java:346)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1065)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:823)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
    at org.eclipse.jetty.server.nio.BlockingChannelConnector$BlockingChannelEndPoint.run(BlockingChannelConnector.java:289)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$1.run(QueuedThreadPool.java:529)
    at java.lang.Thread.run(Thread.java:1012)

I cannot understand what this could be due to, I had also thought about the temporary directory (TempFolder) failing to be used.

Thanks to those who will answer me.

Roberto Sitzia
 

sirjo66

Well-Known Member
Licensed User
Longtime User
Hi Roberto,
I'm Sergio from Vicenza :)

Please show us B4A code of your Server_HandleRequest sub so we can see how you receive the file.

P.S.: are you sure that are necessary these "%2F" that I see in the address bar of the browse ?
 
Last edited:
Upvote 0
Top