android 8+设备上的multipartuploadrequest上载失败(上载时出错)

xyhw6mcr  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(342)

我对多重任务有问题。所有东西都在API较低的设备上运行,但是当设备有android 8或更高版本时,当我想将文件上传到服务器时,它会一直给我错误(“上传时出错”)。在android 8的设备上,它开始发送,但当进度达到100%时,它会给出错误(在android 9的设备上,它甚至不会启动,开始上传时出错)。我以为一切都是因为前台服务缺少通知造成的,但添加时问题仍然出现。
我看到了类似的主题,比如这个(multipartupladRequest(上传时出错)android 10),但它对我没有帮助,因为我使用的是api 18-28,还有这个android 9文件上传(multipartupladRequest)错误,但我已经有了这个权限。
我的代码:

  1. private void uploadMultipart(final Context context){
  2. try{
  3. MultipartUploadRequest uploadRequest = new MultipartUploadRequest(context,SERVER_URL)
  4. .setUtf8Charset()
  5. .setMethod("POST")
  6. .setMaxRetries(0)
  7. .setNotificationConfig(new UploadNotificationConfig())
  8. .addFileToUpload(zipDir.getAbsolutePath()+"/"+emailAddress+".zip","file")
  9. .setDelegate(new UploadStatusDelegate() {
  10. @Override
  11. public void onProgress(Context context, UploadInfo uploadInfo)
  12. {
  13. // Log.i("Progress", String.valueOf(uploadInfo.getProgressPercent()));
  14. asyncResponse.returnProgress(uploadInfo.getProgressPercent());
  15. }
  16. @Override
  17. public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, Exception exception) {
  18. // Log.i("error","error");
  19. asyncResponse.returnHttpStatus(50);
  20. }
  21. @Override
  22. public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
  23. asyncResponse.returnHttpStatus(serverResponse.getHttpCode());
  24. // Log.i("SEND DONE", String.valueOf(serverResponse.getHttpCode()));
  25. }
  26. @Override
  27. public void onCancelled(Context context, UploadInfo uploadInfo) {
  28. // Log.i("Progress","Cancelled");
  29. }
  30. });
  31. .addParameter("email",emailAddress);
  32. // For Android > 8, we need to set an Channel to the UploadNotificationConfig.
  33. // So, here, we create the channel and set it to the MultipartUploadRequest
  34. mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
  35. // Android O requires a Notification Channel.
  36. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  37. CharSequence name = "SPN";
  38. // Create the channel for the notification
  39. NotificationChannel mChannel =
  40. new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT);
  41. // Set the Notification Channel for the Notification Manager.
  42. mNotificationManager.createNotificationChannel(mChannel);
  43. }
  44. uploadRequest.startUpload();
  45. }
  46. catch (Exception e){
  47. errorInSending=true;
  48. }
  49. }

我在asynctask中运行这个函数(在doinbackground函数中)。打电话后 uploadRequest.startUpload(); 它去了一个错误。
我正在使用这个lib的3.4.2版本(https://github.com/gotev/android-upload-service).

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题