共享点冲突行为无法正常工作

时间:2020-03-24 09:25:51

标签: kotlin sharepoint

我正在尝试配置共享点以在再次上载现有文件名时引发异常。为了做到这一点,我试图将@ microsoft.graph.conflictBehavior设置为失败,但是我的测试一直失败,因为没有引发异常。

这是我用来上传文档的Kotlin函数。任何帮助将不胜感激!

private fun upload(document: Document): Document {
        val driveItemUploadableProperties = DriveItemUploadableProperties()
        driveItemUploadableProperties.additionalDataManager()["contentType"] = JsonPrimitive(document.blob.contentType())
        driveItemUploadableProperties.additionalDataManager()["@microsoft.graph.conflictBehavior"] = JsonPrimitive("fail")

        val iDriveItemCreateUploadSessionRequest = buildDriveItemRequest(document.path).createUploadSession(driveItemUploadableProperties).buildRequest()
        val uploadSession = retry { refreshToken { iDriveItemCreateUploadSessionRequest.post() } }

        val provider = ChunkedUploadProvider(uploadSession, microsoftGraphClient, ByteArrayInputStream(document.blob.decode()), document.blob.decode().size, DriveItem::class.java)

        provider.upload(listOf(QueryOption("@microsoft.graph.conflictBehavior", "fail")), object : IProgressCallback<DriveItem> {
            override fun progress(current: Long, max: Long) {
                logger.trace { "Upload progress [${document.path}]: $current done of $max." }
            }

            override fun success(result: DriveItem?) {
                document.id = result?.id
                logger.trace { "Upload done [${document.path}]" }
            }

            override fun failure(ex: ClientException?) {
                when {
                    ex is GraphServiceException && ex.responseCode == HttpStatus.CONFLICT.value() -> throw ConflictException(null, ex.message)
                    ex != null -> throw ex
                    else -> error("Failure reported without exception")
                }
            }
        })

        return document
    }

0 个答案:

没有答案