angela83
angela83

Reputation: 61

Microsoft Graph SDK OneDrive uploadSession Error code:BadRequest

I am trying to upload a file to OneDrive special folder using the java sdk but I am getting the following error

Error code: BadRequest Error message: Multiple action overloads were found with the same binding parameter for 'microsoft.graph.createUploadSession'.

Here is a snippet of the java code I am using

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;
    }
}

Any help appreciated. Thanks

Upvotes: 2

Views: 701

Answers (1)

angela83
angela83

Reputation: 61

My issue is that I had special characters in the filename, removing them fixed it for me.

Upvotes: 3

Related Questions