gotev/android-upload-service

Not getting events on subscribe onProgress onSuccess etc

saurabhverma2892 opened this issue · 2 comments

Everything works well, but I am not getting events when subscribed to the request.
Also, when subscribed, there is no need to request.startUpload()?

mContext here is the context of the activity which i am sending in a class to call this api where the code below is implemented

MultipartUploadRequest request = new MultipartUploadRequest(mContext, url + "/home")
                        .addParameter("description", params.getString("description"))
                        .addParameter("monthlyPrice", params.getString("monthlyPrice"))
                        .addParameter("roomType", params.getString("roomType"))
                        .addParameter("roomsCount", params.getString("roomsCount"))
                       

                JSONArray mediaarray = params.getJSONArray("media");

                for(int i=0;i<mediaarray.length();i++){
                    JSONObject mediaFile = mediaarray.getJSONObject(i);
                    String path = mediaFile.getString("path");
                    request.addFileToUpload(path, "files[]");
                }


UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig(
                        Initializer.getMessageId(),
                        false,
                        new UploadNotificationStatusConfig(
                                "progress",
                                "some progress message"
                        ),
                        new UploadNotificationStatusConfig(
                                "success",
                                "some success message"
                        ),
                        new UploadNotificationStatusConfig(
                                "error",
                                "some error message"
                        ),
                        new UploadNotificationStatusConfig(
                                "cancelled",
                                "some cancelled message"
                        )
                );

request.addHeader("Authorization",User.getToken())
                        .setMethod("POST")
                        .setMaxRetries(5)
                        .setNotificationConfig((context, uploadId2)-> uploadNotificationConfig);
                
request.subscribe(mContext,` (LifecycleOwner) mContext, new RequestObserverDelegate() {
                            @Override
                            public void onSuccess( Context context, UploadInfo uploadInfo, @NotNull ServerResponse serverResponse) {
                                Log.i("adding house","onSuccess");
                            }

                            @Override
                            public void onError(@NotNull Context context, @NotNull UploadInfo uploadInfo, @NotNull Throwable throwable) {
                                Log.i("adding house","onError");
                            }

                            @Override
                            public void onCompletedWhileNotObserving() {
                                Log.i("adding house","onCompletedWhileNotObserving");
                            }

                            @Override
                            public void onCompleted(@NotNull Context context, @NotNull UploadInfo uploadInfo) {
                                
                                Log.i("adding house","uploadInfo");
                                
                            }

                            @Override
                            public void onProgress(Context mContext, UploadInfo uploadInfo) {
                                // do your thing
                                mProgressDialog.dismiss();
                                Log.i("adding house","onProgress");
                                
                            }

                        });


I get success message in the logs, but none of my logs, none of the events gets called.

I/UploadService: UploadTask - (uploadId: 720d4024-6e64-4fa2-9f06-1ccb961c64aa) - upload completed
I/UploadService: UploadService - (uploadId: 720d4024-6e64-4fa2-9f06-1ccb961c64aa) - now un-holded foreground notification
I/UploadService: UploadService - (uploadId: N/A) - All tasks completed, stopping foreground execution
I/UploadService: UploadService - (uploadId: N/A) - Service will be shut down in 10000s if no new tasks are received
V/FA: Inactivity, disconnecting from the service

gotev commented

When you subscribe the upload event is started, so no need to invoke anything else.

That cast to LifecycleOwner looks suspicious to me. You shouldn't need that, as it's an interface already implemented by AppCompatActivity, which I suggest you to use.

Please also take a look at: https://github.com/gotev/android-upload-service/wiki/Monitor-Uploads

Where lifecycle is described in detail.

You are right. LifeCycleOwner was the issue. Thanks alot!