javaandroidmicrosoft-graph-apionedrive

Microsoft graph - upload small files to OneDrive with customized cconflict resolution behvior


I am working on development of my Android java application which utilizes Microsoft graph API to upload files to OneDrive. I see the offical article mentions: enter image description here It seems that it's feasible to upload small files to Onedrive with a customized confliction resolution behavior by PUT request. Does anyone know how to make such a request with a customized confliction resolution behavior? Currently I am using graph sdk to make my life easier. It's even better someone can provide me code example to achive that.

What I have tried: Graph sdk PUT request with customized request option:

FunctionOption option = new FunctionOption("@microsoft.graph.conflictBehavior",new JsonPrimitive("rename"));

mClient.getGraphServiceClient().me().drive().items(parent)
    .itemWithPath("/" + mMetaData.getName())
    .content()
    .buildRequest(option)            
    .put(stream);

Expected: file can be uploaded with error Actual result: 400 Bad Request


Solution

  • Typically a ‘400 Bad Request” indicates that the request cannot be processed because it is incorrect or malformed -which includes the malformed request syntax or invalid framing of the request.For the errors here is a Link to documentation here

    In your case, it seems the way you're passing the conflict behavior option might be the reason for the error you are encountering.

    Ensure that the parameter @microsoft.graph.conflictBehavior is included in the URL instead of the body of the request as mentioned in the Notes section of the documentation here. Here is a link to Github sample showing how to upload a small file with conflictBehavior set on the official doc guides.