Page 1 of 1

Cannot resolve method getHttpUploadURI

Posted: 02 Jun 2016, 18:04
by noveltysoft
Hi

I am working on a android application, one like whatsapp. I am using SFS API 1.6.1. I need to upload files to share with other users so i looked into sfs docs and found this tutorial http://docs2x.smartfoxserver.com/Advanc ... le-uploads. when i am using the same java code mention in the official documentation, but my IDE cannot resolve the method getHttpUploadURL. Here is the screenshot of relevant code from my my application which is exactly same as the docx says.

Image

one more thing to mention, client is already logged in to server before calling this method, and client can perform almost every other task except calling this method. can someone help me on this?

Re: Cannot resolve method getHttpUploadURI

Posted: 03 Jun 2016, 09:33
by Lapo
Hi,
I don't know what the problem could be, but I have no problem with the method.
I downloaded the 1.6.1 Api from the website, created a new NetBeans project and it works as expected. See attached screenshot.

May try to download the library again?
http://smartfoxserver.com/download/sfs2x#p=client

nbeans.png
(216.37 KiB) Not downloaded yet

Re: Cannot resolve method getHttpUploadURI

Posted: 03 Jun 2016, 13:58
by noveltysoft
thank you. that helped me. Deleting .jar files inside libs folder and re importing fixed the issue for me. now i wanna ask another thing about passing custom parameters with with my upload request to receive those parameters inside SFSEventType.FILE_UPLOAD.

what i am doing right now is passing parameters with upload URI separating by & sign.

Code: Select all

new HttpPost(sfsClient.getHttpUploadURI() + "&__roomName=" + room.getName()+ "&__roomId=" + room.getId());
which gives me

FATAL EXCEPTION: main

Code: Select all

Process: com.mgh.mghmessenger, PID: 9738
                                                                    java.lang.RuntimeException: Unable to start service com.mgh.mghmessenger.services.FileUpload@3237179b with null: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
                                                                        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3457)
                                                                        at android.app.ActivityThread.access$2200(ActivityThread.java:181)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:145)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:6145)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at java.lang.reflect.Method.invoke(Method.java:372)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                                     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
                                                                        at com.mgh.mghmessenger.services.FileUpload.onStartCommand(FileUpload.java:69)
                                                                        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3440)
                                                                        at android.app.ActivityThread.access$2200(ActivityThread.java:181) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:145) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:6145) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 


and everything works without passing parameter. like

Code: Select all

new HttpPost(sfsClient.getHttpUploadURI());


by debugging i made sure that variables i am passing to HttpPost are not null. can u plz help me on this?

Re: Cannot resolve method getHttpUploadURI

Posted: 03 Jun 2016, 15:02
by Lapo
I recommend checking the docs here:
http://docs2x.smartfoxserver.com/Advanc ... le-uploads

custom parameters must be sent via POST, not via GET (e.g. as query string params)

Hope it helps

Re: Cannot resolve method getHttpUploadURI

Posted: 03 Jun 2016, 15:27
by noveltysoft
yes, i checked these documents and i am passing these parameters in a HTTP POST not in GET as you mentioned. here is the statement i am using to create HTTP POST

Code: Select all

   Room room = sfsClient.getLastJoinedRoom();
   HttpPost httppost = new HttpPost(sfsClient.getHTTPUploadURI + "&__roomName=" + room.getName()+ "&__roomId=" + room.getId());

but its not working for me.

Re: Cannot resolve method getHttpUploadURI

Posted: 03 Jun 2016, 16:46
by Lapo
Have you checked why the NullPointer exception is being thrown?

The error seems to be caused by this, in the wrapped exception:

Code: Select all

at com.mgh.mghmessenger.services.FileUpload.onStartCommand(FileUpload.java:69)
 at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3440)
 at android.app.ActivityThread.access$2200(ActivityThread.java:181)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:145)
 at android.app.ActivityThread.main(ActivityThread.java:6145)
 at java.lang.reflect.Method.invoke(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:372)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)


What happens at line 69 of FileUpload.java?

Re: Cannot resolve method getHttpUploadURI

Posted: 03 Jun 2016, 17:05
by noveltysoft
in line number 69, i am receiving an intent extra. this is my line number 69.

Code: Select all

filePath = i.getStringExtra("filePath");

and i tested this again, intent extra is passed and received properly. so filePath variable isn't null.

Re: Cannot resolve method getHttpUploadURI

Posted: 04 Jun 2016, 07:01
by Lapo
I don't know... that's where the error you have posted is pointing to... unless you have changed your code after posting the error and we're looking at the wrong line.

I can only suggest to run your code again and if the same exception occurs go check the line that the stack trace indicate... maybe post it here too.

thanks

Re: Cannot resolve method getHttpUploadURI

Posted: 06 Jun 2016, 10:55
by noveltysoft
Hi
finally figured out what's going wrong. the problem is the parameter i am passing in post request contains a space.

Code: Select all

http://192.168.0.100:8080/BlueBox/SFS2XFileUpload?sessHashId=9a0162bfe3c2b7750ec2dfc9bc234523&__roomName=Group 1&__roomId=8

see. there is a space between roomName which is 'Group 1'. if i remove space. 'Group1' works very well. so my question is how can i work with this space. there can be multiple space in room name like 'SFS Room 1'. so plz tell me how to deal with this issue. without space every thing works fine.

Re: Cannot resolve method getHttpUploadURI

Posted: 06 Jun 2016, 15:19
by Lapo
You need to url-encode the string so that special characters, such as spaces, get translated to the proper entities.
See here:
http://stackoverflow.com/questions/1078 ... parameters

cheers

Re: Cannot resolve method getHttpUploadURI

Posted: 07 Jun 2016, 09:41
by noveltysoft
this is how i am passing parameters now.

Code: Select all

httppost = new HttpPost(uploadURI + "&__roomName=" + URLEncoder.encode(room.getName(), "UTF-8")  + "&__roomId=" + room.getId());

and it is working. thanks Lapo