Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple File Upload Notification #243

Closed
markusf opened this issue Mar 2, 2017 · 23 comments
Closed

Multiple File Upload Notification #243

markusf opened this issue Mar 2, 2017 · 23 comments
Labels
feature request Issue with request of new features question A question or a support request

Comments

@markusf
Copy link

markusf commented Mar 2, 2017

Hey,

is there a way to show a notification, which is handling the total progress for multiple file upload (using multiple requests) out of the box?

Best regards

@gotev
Copy link
Owner

gotev commented Mar 2, 2017

I'd love to see a PR with that feature!

@gotev gotev added the question A question or a support request label Mar 3, 2017
@gotev gotev changed the title Question: Multiple File Upload Notifiation Multiple File Upload Notification Mar 3, 2017
@gotev gotev added the feature request Issue with request of new features label Mar 4, 2017
@mostafaspace
Copy link

Hello,

In the topic of Multiple File Upload Notifiation, I've been trying to reach a notification like this:
http://i.imgur.com/bsV3rRd.png

Is this is possible with the current notification config or It can't be done?

Thanks.

@gotev
Copy link
Owner

gotev commented Mar 26, 2017

yes, a multipart upload request with threee files

@mostafaspace
Copy link

Thanks so much for you answer,

Can you tell me where to look about making 1 by 1 progress?

And is this what you mean?
for (String photo : selectedPhotos){ uploadRequest.addFileToUpload(photo, "image[]"); }

Thanks.

@gotev
Copy link
Owner

gotev commented Mar 27, 2017

You can use placeholders in notification messages. https://github.com/gotev/android-upload-service/wiki/Recipes#notification-configuration

@gotev
Copy link
Owner

gotev commented Mar 27, 2017

And yes, you can add multiple files like that

@mostafaspace
Copy link

Hello,
Thank you so much.

I tried it and its ok, but I find it difficult to track upload errors, Tried to get callbacks from server and then update the notification error, but it didn't work as I need it to. So I just added the whole request in the for loop and send 1 request for each image, this way I get single notification for each image for failed messages..

One other thing, in the image[] way , the progress bar is combining the whole request, not uploading them 1 by 1. What I had in mind was a progress bar for each uploaded file, and only if failed it gets own notification with the file name and the reason.

Thank you for your great work ;)

@gotev
Copy link
Owner

gotev commented Mar 28, 2017

So, you need something a library doesn't support yet: multiple parallel multipart requests which has to be aggregated on a single notification, but with separate error handlers for each upload. To support that, a library redesign may be needed and your help is greatly appreciated.

@mostafaspace
Copy link

mostafaspace commented Mar 28, 2017

I'm not really sure what to call it. But here I'll try to simplify what I mean:

-Send all photos in one request using image[]
-Upload each of them 1 by 1, but in one notification bar e.g. 1 of 3 (http://i.imgur.com/bsV3rRd.png)
-Each photo of them has its own progress bar and error callback
-If has error, show the error and file name in a new notification

I think i reached that but without the "one request" nor "error callbacks" part.
http://i.imgur.com/LCodsGW.png
For now I added .setAutoClearOnSuccess(true) to leave only the errors, and I have only mime-type and file-size checks, so I just wrote the "might" be too large error and Photopicker picks only photos. but in case there is more checks, it needs to read from a server callback better.

Overall, it works fine, It just needed to be more accurate for the user to know the exact error and the file name so he can take the needed action.

Thank you so much

@gotev
Copy link
Owner

gotev commented Mar 29, 2017

if you send all the images in a single request, you can't make 1 by 1 uploads, because all the files are added in the same request. That's how multipart works. Also, since the multipart request is not resumable, if at some point the upload fails, you have to start over from the beginning. To make 1 by 1 uploads you will have to make N Multipart requests and handle each one of them separately.

If you want to have N multipart requests, but see their progress in a single notification with overall progress, it has to be implemented.

Being said that, if you have a single multipart request, you can display the total number of files and the uploaded files with the following upload notification config:

protected UploadNotificationConfig getNotificationConfig() {
    return new UploadNotificationConfig()
            .setInProgressMessage(Placeholders.UPLOADED_FILES + " of " + 
                                  Placeholders.TOTAL_FILES + ". Speed: " + 
                                  Placeholders.UPLOAD_RATE)
            .setCompletedMessage("upload completed")
            .setErrorMessage("error while uploading files")
            .setCancelledMessage("upload aborted")
            .setRingToneEnabled(true);
}

in case there is more checks, it needs to read from a server callback better.

What do you mean by read from a server callback better?

From my point of view, the better choice for more complex use cases is to use the broadcast receivers, either globally or inside an activity, depending on your use case. Both are documented here. You can have whatever checks you need in the onCompleted where you have the HTTP status and response body from the server.

@mostafaspace
Copy link

I get what you mean, so lets forget about the image[] and send one photo per request.

What I mean by read from server callbacks is each request does send a callback in the onCompleted but in case there is an error, can you update the notification error to be the message of onCompleted?

@gotev
Copy link
Owner

gotev commented Mar 31, 2017

@mostafaspace maybe #259 addresses exactly what you need

@azizarc88
Copy link

Hello,

Can you please help me..?
i just try your library using MultipartUploadRequest
but i got an error, it say

java.lang.NoSuchMethodError: No direct method <init>(Landroid/content/Context;Ljava/lang/String;)V in class Landroid/support/v4/app/NotificationCompat$Builder; or its super classes (declaration of 'android.support.v4.app.NotificationCompat$Builder' appears in /data/app/com.sigapp.id-2/base.apk)

and i using com.android.support:support-v4:25.+

Thanks before.

@gotev
Copy link
Owner

gotev commented Aug 21, 2017

@azizarc88 open a new issue instead of posting here, thanks

@zoptaltechnical
Copy link

I am unable to upload multiple files due to lack of code example , Please provide complete code to upload multiple files, Correct me if i have missed anything , Thanks

@PhilLab
Copy link
Contributor

PhilLab commented Jul 23, 2018

@zoptaltechnical This is the code example you are looking for: https://github.com/gotev/android-upload-service/wiki/Recipes#multipart . Just calladdFileToUpload() multiple times. But please be so kind and don't use this issue for further questions regarding this multipart upload as it is about a (slightly) different feature. If you experience additional difficulties, maybe StackOverflow can help

@PhilLab
Copy link
Contributor

PhilLab commented Sep 3, 2018

@gotev Do you have plans for the

multiple parallel multipart requests which has to be aggregated on a single notification

right now or would this be something open for community contributions?
You said this would need a library redesign - will this feature really mean widespread code changes?

@gotev
Copy link
Owner

gotev commented Sep 3, 2018

Unfortunately I don't have plans to do it myself due to lack of time, but contributions are always welcome, so feel free to make your own implementation and send a PR

Repository owner deleted a comment from ChadhaAashish Jan 17, 2019
@gotev
Copy link
Owner

gotev commented Jan 17, 2019

Closing this due to lack of contributions so far. Feel free to reopen it if you have a PR ;)

@gotev gotev closed this as completed Jan 17, 2019
@PhilLab
Copy link
Contributor

PhilLab commented Jun 4, 2020

@gotev is this something which is contained in / easier to solve in UploadService 4?

@gotev
Copy link
Owner

gotev commented Jun 4, 2020

@PhilLab
Copy link
Contributor

PhilLab commented Jun 4, 2020

@gotev This are very good news, thanks for the effort you put in 👍 We will start moving from version 3 to 4, I guess 😄

@gotev
Copy link
Owner

gotev commented Jun 4, 2020

@PhilLab it's been a lot of work, but the library needed to be modernized from the ground up. Everything is new down below. It will be interesting if you documented the process and then we can include it in the Wiki (or a Medium/Blog article if you prefer) as a concrete real world migration example. Bear in Mind 4.x has minAPI 21 and other breaking changes but it's definitely worth it from every point of view when compared to 3.x. New Wiki has many guides already. If you miss something, open an issue ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issue with request of new features question A question or a support request
Projects
None yet
Development

No branches or pull requests

6 participants