使用Microsoft图形uploadSession

问题描述

我有一个Android应用程序,该应用程序使用Chunked上传会话将图片文件上传到sharepoint文件夹。通常情况下,这进展顺利,但突然(突然)我收到403禁止消息。这可能发生在尝试中间,其中1-5可以,1可以403,随后的上传可以。这些文件(每个文件大约400 kb),相同的文件夹没有任何区别,每次上传都获得新的accessToken(如果存在)。

其他有相同经验的人,或者MsGraph中是否存在任何(已知/未知)错误?

使用Microsoft依赖项:

    //Microsoft
    //Identity
    implementation ('com.microsoft.identity.client:msal:2.0.2')
            {exclude group: 'com.microsoft.device.display'}

    //Graph
    implementation 'com.microsoft.graph:microsoft-graph:2.3.1'

代码段(kotlin)

上传会话:


                            val uploadSession = safeGraphServiceClient
                                .sites(CONST_SHAREPOINT_SITE_ID)
                                .drive()
                                .root()
                                .itemWithPath(itemWithPath)
                                .createUploadSession(DriveItemUploadableProperties())
                                .buildRequest()
                                .post()


                            val fileStream = FileInputStream(uri.path)

                            try {


                                ChunkedUploadProvider(
                                    uploadSession,safeGraphServiceClient,fileStream,fileStream.available().toLong(),DriveItem::class.java
                                ).upload(object : IProgressCallback<DriveItem?> {
                                    override fun success(result: DriveItem?) {
                                        Log.i(TAG,"success: upload success ${result.toString()}")
                                        Message.info("Picture successfully uploaded")

                                        //Delete file after upload
                                        uri.path?.let { safePath ->
                                            val fdelete = File(safePath)
                                            if (fdelete.exists()) {
                                                if (fdelete.exists()) {
                                                    if (fdelete.delete()) {
                                                        Log.i(TAG,"success: file $fdelete deleted from device")
                                                    } else {
                                                        Log.e(TAG,"success: could not delete file $fdelete transferred file from device")
                                                        Message.warning("Could not delete file after transfer")
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    override fun failure(ex: ClientException?) {

                                        Log.e(TAG,"failure: upload failure",ex)
                                        Message.error("Error when uploading picture $itemWithPath")
                                    }

                                    override fun progress(current: Long,max: Long) {
                                        Log.i(TAG,"progress: upload progress $current of $max")
                                        Message.info("Upload progress $current of $max")
                                    }

                                },*intArrayOf(320 * 1024))
                            } catch (exception: Exception) {
                                Log.e(TAG,"uploadPicture2: upload picture Exception !! should be possible to retry",exception)
                            }


访问令牌功能:


    suspend fun generateAccessToken(microsoftAccountViewModel: MicrosoftAccountViewModel):String?
    {
        Log.i(TAG,"generateAccessToken: generateAccessToken")
        var accessToken: String?=null
        microsoftAccountViewModel.apply {
            singleAccountAppMLD.value?.let { singleAccountApp ->
                accessScopesMLD.value?.let { accessScopes ->
                    accessAuthorityMLD.value?.let { accessAuthority->
                        withContext(Dispatchers.IO){
                            val iAuthenticationResult
                                    = singleAccountApp.acquireTokenSilent(
                                    accessScopes,accessAuthority)
                            accessToken = iAuthenticationResult.accessToken
                            Log.i(TAG,"generateAccessToken: accessToken achieved = $accessToken")
                        }
                    }
                }
            }
        }
        return accessToken
    }
}

...或者我使用该函数的方式有误(很奇怪,因为它可以进行85%的尝试)。

RG

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...