Cannot resolve method getHttpUploadURI

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

noveltysoft
Posts: 39
Joined: 19 Sep 2012, 03:24

Cannot resolve method getHttpUploadURI

Postby noveltysoft » 02 Jun 2016, 18:04

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?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot resolve method getHttpUploadURI

Postby Lapo » 03 Jun 2016, 09:33

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
Lapo
--
gotoAndPlay()
...addicted to flash games
noveltysoft
Posts: 39
Joined: 19 Sep 2012, 03:24

Re: Cannot resolve method getHttpUploadURI

Postby noveltysoft » 03 Jun 2016, 13:58

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?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot resolve method getHttpUploadURI

Postby Lapo » 03 Jun 2016, 15:02

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
Lapo

--

gotoAndPlay()

...addicted to flash games
noveltysoft
Posts: 39
Joined: 19 Sep 2012, 03:24

Re: Cannot resolve method getHttpUploadURI

Postby noveltysoft » 03 Jun 2016, 15:27

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.
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot resolve method getHttpUploadURI

Postby Lapo » 03 Jun 2016, 16:46

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?
Lapo

--

gotoAndPlay()

...addicted to flash games
noveltysoft
Posts: 39
Joined: 19 Sep 2012, 03:24

Re: Cannot resolve method getHttpUploadURI

Postby noveltysoft » 03 Jun 2016, 17:05

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.
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot resolve method getHttpUploadURI

Postby Lapo » 04 Jun 2016, 07:01

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
Lapo

--

gotoAndPlay()

...addicted to flash games
noveltysoft
Posts: 39
Joined: 19 Sep 2012, 03:24

Re: Cannot resolve method getHttpUploadURI

Postby noveltysoft » 06 Jun 2016, 10:55

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.
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot resolve method getHttpUploadURI

Postby Lapo » 06 Jun 2016, 15:19

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
Lapo

--

gotoAndPlay()

...addicted to flash games
noveltysoft
Posts: 39
Joined: 19 Sep 2012, 03:24

Re: Cannot resolve method getHttpUploadURI

Postby noveltysoft » 07 Jun 2016, 09:41

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

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 15 guests