Upload Service on ACL: No Authentication Challenges Found

0 votes

I am trying to upload a file (JPEG) using the upload service in my ACL enabled Android app.

The problem is I keep on getting java.io.IOException: No Authentication Challenges Found, thus indicating some sort of authentication issues with my app.

But I am authenticating the user in the onCreate() method itself and then I call the method to upload the file.

Also if I use uploadFileForUser() method, file gets uploaded successfully. And if I upload file in my ACL disabled app, file gets uploaded without any issues.

So there has to be something that I am missing for sure. Please someone share it if you have any idea of what's going on.

This is the code I wrote:

//For Authentication:

final UserService userService = App42API.buildUserService();
        userService.getUser("Sagar Sheokand", new App42CallBack() {

            @Override
            public void onSuccess(Object arg0) {
                userService.authenticate("Sagar Sheokand", "Sagar", new App42CallBack() {

                    @Override
                    public void onSuccess(Object arg0) {
                        User user = (User)arg0;
                        System.out.println("User: Sagar Sheokand Authenticated");
                        userService.setSessionId(user.getSessionId());
                        fileUpload();
                    }

                    @Override
                    public void onException(Exception arg0) {
                        System.out.println("---User Sagar Sheokand not Authenticated---");                        
                    }
                });

// For File Upload:

final UploadService uploadService = App42API.buildUploadService();

uploadService.uploadFile(s, path, UploadFileType.IMAGE, "photo", new App42CallBack() {

                                @Override
                                public void onSuccess(Object arg0) {
                                    // TODO Auto-generated method stub
                                    //arg0.toString();
                                }

                                @Override
                                public void onException(Exception arg0) {
                                    // TODO Auto-generated method stub
                                    arg0.printStackTrace();
                                }
                            });

asked May 26, 2014 in App42 Cloud API-BaaS by sagarsheokand (16 points)

1 Answer

0 votes

Hi Sagar,

Thanks for sharing the code snippet.

Firstly i need to tell you that you need to pass the SessionId in upload service object for uploading the file in ACL enable app because what i have seen is your code doesn't set the sessionId in upload service object.

That is why when you are uploading the file in ACL disable app your file is being uploaded onto our server.

And also i will recommend you that download the latest SDK  from here.

answered May 27, 2014 by hs00105 (517 points)
Thanks. I will follow your advice and if it works I will select this answer.
EDIT: Also about latest SDK, I started using APP42 a week ago so do I need to update? And where do I find update notice to keep me updated?
You can check the release updates from this link given below :-https://github.com/shephertz/App42_ANDROID_SDK/blob/master/Change_Log.md

And also use the code snipped given below for uploading the file in ACL app by setting the sessionId of user in upload service object :-

final UploadService uploadService = App42API.buildUploadService();
uploadService .setSessionId("SessionId of User");
String fileName = "<Your_file_name>";
String userName = "Nick";
String description = "File Description";   
String filePath = "Your Local File Path";   
uploadService.uploadFileForUser(fileName,userName, filePath, UploadFileType.IMAGE, description, new App42CallBack() {
public void onSuccess(Object response)
{
    Upload upload = (Upload)response;                       
    ArrayList<Upload.File>  fileList = upload.getFileList();   
    for(int i = 0; i < fileList.size();i++ )  
    {  
        System.out.println("fileName is :" + fileList.get(i).getName());  
        System.out.println("fileType is :" + fileList.get(i).getType());  
        System.out.println("fileUrl is :" + fileList.get(i).getUrl());  
        System.out.println("Tiny Url is :"+fileList.get(i).getTinyUrl());
        System.out.println("fileDescription is: " + fileList.get(i).getDescription());
    }   
}
public void onException(Exception ex)
{
    System.out.println("Exception Message"+ex.getMessage());   
}
});
First of all, please edit the 'github' address you provided, you forgot to give a space after 'Log.md' at the end of the link. It would be useful for future readers.
Also I mentioned in my question that I already tried uploadFileForUser() & uploadFileForGroup() methods and they worked flawlessly but the method uploadFile() won't work.

Do I need to give name of user or group compulsorily? Sorry if I sound too noob, I tend to ask novice questions, specially at 3.50 a.m. :)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...