-
-
Notifications
You must be signed in to change notification settings - Fork 687
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
duplicate uploadID #661
Comments
The code you posted seems correct at first glance, but since you're getting
that error, it means that two or more requests have been made with the same
uploadId, that's an internal protection of the lib, so check the rest of
your code to be sure to not have a fixed uploadId somewhere and to not have
duplicate requests being made (for example a quick double tap by the user).
Also, if all your uploads needs the same notification config, better to use
the notification config factory method (check the configuration wiki).
Il gio 25 apr 2024, 20:42 keyvan ***@***.***> ha scritto:
… Hi ,
*Describe the bug*
I am using the upload manager in my fragment but I get You have tried to
perform startUpload() using the same uploadID of an " +
"already running task. You're trying to use the same ID for multiple
uploads.
error message when debugging the app
*To Reproduce*
public class App extends Application {
UploadServiceConfig.initialize(this, App.CHANNEL, BuildConfig.DEBUG);
UploadServiceConfig.setHttpStack(new OkHttpStack(getOkHttpClient()));
UploadServiceConfig.setRetryPolicy(new RetryPolicyConfig(1, 10, 2, 3));
}
`
public class photoFragment extends Fragment {
protected UploadNotificationConfig getNotificationConfig(final String
uploadId, @StringRes int title) {
PendingIntent clickIntent = PendingIntent.getActivity(
getActivity(), 1, new Intent(getContext(), photoFragment.class),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
final boolean autoClear = false;
final boolean clearOnAction = true;
final boolean ringToneEnabled = true;
final ArrayList<UploadNotificationAction> noActions = new ArrayList<>(1);
final UploadNotificationAction cancelAction = new UploadNotificationAction(
R.drawable.ic_cancelled,
getString(R.string.cancel_upload),
ContextExtensionsKt.getCancelUploadIntent(getContext(), uploadId)
);
final ArrayList<UploadNotificationAction> progressActions = new ArrayList<>(1);
progressActions.add(cancelAction);
UploadNotificationStatusConfig progress = new UploadNotificationStatusConfig(
getString(title),
getString(R.string.uploading),
R.drawable.ic_upload,
Color.BLUE,
null,
clickIntent,
progressActions,
clearOnAction,
autoClear
);
UploadNotificationStatusConfig success = new UploadNotificationStatusConfig(
getString(title),
getString(R.string.upload_success),
R.drawable.ic_upload_success,
Color.GREEN,
null,
clickIntent,
noActions,
clearOnAction,
autoClear
);
UploadNotificationStatusConfig error = new UploadNotificationStatusConfig(
getString(title),
getString(R.string.upload_error),
R.drawable.ic_upload_error,
Color.RED,
null,
clickIntent,
noActions,
clearOnAction,
autoClear
);
UploadNotificationStatusConfig cancelled = new UploadNotificationStatusConfig(
getString(title),
getString(R.string.upload_cancelled),
R.drawable.ic_cancelled,
Color.YELLOW,
null,
clickIntent,
noActions,
clearOnAction
);
return new UploadNotificationConfig(App.CHANNEL, ringToneEnabled, progress, success, error, cancelled);
}
try{
MultipartUploadRequest request = new MultipartUploadRequest(context2,
serverUrl)
.addFileToUpload(String.valueOf(filePath),"file")
.setMethod("POST")
.setNotificationConfig((context,
uploadId)->getNotificationConfig(uploadId, R.string.app_name))
.setMaxRetries(2);
request.startUpload();
} catch (Exception exc) {
Log.e(TAG, exc.getMessage(), exc);
}
}
`
*Expected behavior*
A clear and concise description of what you expected to happen.
*OS and Lib versions (please complete the following information):*
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "1"
—
Reply to this email directly, view it on GitHub
<#661>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEADXLYPF3A656U4IFZAXJLY7FFAFAVCNFSM6AAAAABGZNPY5SVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI3DIMRWGQ4DKMA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
The breakpoint only hits once I will post the whole fragment though |
here is the whole fragment:
|
The problem may be because in your case you invoke the camera and the onActivityResult is handled in the fragment instead of in the activity containing the fragment. Android best practices suggest an approach like this public class YourFragment extends Fragment {
private static final int REQUEST_CODE = 123;
// Your fragment code...
public void startForResult() {
Intent intent = new Intent(getActivity(), YourActivity.class);
startActivityForResult(intent, REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE) {
// Delegate result handling to the parent activity
((YourActivity) getActivity()).handleActivityResult(resultCode, data);
}
}
} Parent activity public class YourActivity extends AppCompatActivity {
// Your activity code...
public void handleActivityResult(int resultCode, Intent data) {
// Handle the result here
if (resultCode == Activity.RESULT_OK) {
// Handle successful result
} else {
// Handle unsuccessful result
}
}
} Or better, delegate the whole StartActivityForResult and result handling to the parent activity, and start upload from there. Fragments have often inconsistent lifecycles unfortunately. As a further debug utility, you can log UploadService.taskList which contains all the currently active tasks. |
I found something interesting even if put the 'upload part ONLY' in another activity it gives the same error:duplicateUpliad id! |
Check how you are performing the init of the library |
To my surprise the code below works
|
I see quite old libraries used there I wouldn't recommend to be used in 2024 android development (like ButterKnife). Latest upload service is 4.9.2. I recommend you to use that instead. What you're experiencing is surely because of some underlying lifecycle problems which are beyond the scope of the lib, given the evidence I've seen so far. |
Hi ,
Describe the bug
I am using the upload manager in my fragment but I get You have tried to perform startUpload() using the same uploadID of an " +
"already running task. You're trying to use the same ID for multiple uploads.
error message when debugging the app
To Reproduce
OS and Lib versions (please complete the following information):
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "1"
I need to app to upload successfully but it is not!
The text was updated successfully, but these errors were encountered: