Microsoft Graph SDK OneDrive uploadSession错误代码:BadRequest

问题描述

我正在尝试使用java sdk将文件上传到OneDrive特殊文件夹,但是出现以下错误

错误代码:BadRequest错误消息:为“ microsoft.graph.createUploadSession”使用相同的绑定参数发现了多个操作重载。

这是我正在使用的Java代码一个片段

private void uploadFile(IGraphServiceClient graphClient,File localFile,String onedriveFileName) throws IOException,InterruptedException {
    // Get an input stream for the file
    InputStream fileStream = new FileInputStream(localFile);
    long streamSize = localFile.length();

    // Create a callback used by the upload provider
    IProgressCallback<DriveItem> callback = new IProgressCallback<DriveItem>() {
        @Override
        // Called after each slice of the file is uploaded
        public void progress(final long current,final long max) {
            LOGGER.trace(String.format("Uploaded %d bytes of %d total bytes",current,max));
        }

        @Override
        public void success(final DriveItem result) {
            LOGGER.info(String.format("Uploaded file with ID: %s",result.id));
        }

        public void failure(final ClientException ex) {
            LOGGER.error(String.format("Error uploading file: %s",ex.getMessage()));
        }
    };

    try {
        // Create an upload session
        UploadSession uploadSession = graphClient
                .me()
                .drive().special("approot")
                .itemWithPath(onedriveFileName)
                .createUploadSession(new DriveItemUploadableProperties())
                .buildrequest()
                .post();

        ChunkedUploadProvider<DriveItem> chunkedUploadProvider =
                new ChunkedUploadProvider<DriveItem>
                        (uploadSession,graphClient,fileStream,streamSize,DriveItem.class);

        // Config parameter is an array of integers
        // customConfig[0] indicates the max slice size
        // Max slice size must be a multiple of 320 KiB
        int[] customConfig = {320 * 1024};

        // Do the upload
        chunkedUploadProvider.upload(callback,customConfig);

    } catch(IOException ex){
        throw ex;
    } catch (Exception  ex) {
        throw ex;
    }
}

任何帮助表示赞赏。 谢谢

解决方法

我的问题是我的文件名中有特殊字符,删除它们为我修复了它。