microsoftgraph / msgraph-sdk-android

Microsoft Graph SDK for Android! https://graph.microsoft.io
Other
51 stars 43 forks source link

Error trying to copy a file #14

Closed diogowbrito closed 7 years ago

diogowbrito commented 8 years ago

I'm trying to copy a file inside the One Drive filesystem.

The code I'm using is the following:

private void copy(DriveItem driveItem, DriveItem destinationDriveItem) {
    String name = driveItem.name;
    ItemReference itemReference = new ItemReference();
    itemReference.id = destinationDriveItem.id;
    mClient.getMe().getDrive().getItems(driveItem.id).getCopy(name, parentReference).buildRequest().post();
}

I'm not even clear this is way, given the lack of SDK documentation, but according to this documentation it looks like the most similar one.

However, I get the following error:

Error during http request Error code: invalidRequest
Error message: Cannot call Copy without the respond-async preference
POST https://graph.microsoft.com/v1.0/me/drive/items/3FCC79A25960915F!116/microsoft.graph.copy
SdkVersion : graph-android-v0.9.2
Authorization : bearer EwC4Asl6BAAU1sPaz/0rP7ovs9b[...]
{"parentReference":{"id":"3FCC79A25960915F!106","@[...]
400 : Bad Request
[...]
[Some information was truncated for brevity, enable debug logging for more details]
Throwable detail: 
com.microsoft.graph.http.GraphServiceException: Error code: invalidRequest
Error message: Cannot call Copy without the respond-async preference
POST https://graph.microsoft.com/v1.0/me/drive/items/3FCC79A25960915F!116/microsoft.graph.copy
SdkVersion : graph-android-v0.9.2
Authorization : bearer EwC4Asl6BAAU1sPaz/0rP7ovs9b[...]
{"parentReference":{"id":"3FCC79A25960915F!106","@[...]
400 : Bad Request
[...]
[Some information was truncated for brevity, enable debug logging for more details]
    at com.microsoft.graph.http.DefaultHttpProvider.handleErrorResponse(DefaultHttpProvider.java:310)
    at com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(DefaultHttpProvider.java:246)
    at com.microsoft.graph.http.DefaultHttpProvider.access$000(DefaultHttpProvider.java:47)
    at com.microsoft.graph.http.DefaultHttpProvider$1.run(DefaultHttpProvider.java:129)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)

Am I calling the wrong SDK methods? What might be wrong? By the way, it would be a huge enhancement to include more documentation/samples.

peternied commented 8 years ago

OneDrive's item copy is not supported with the MSGraph SDK at this time.

diogowbrito commented 8 years ago

@peternied do you know when it will be?

peternied commented 8 years ago

Unfortunately I do not have a time table for when this SDK will support async features.

iambmelt commented 7 years ago

This functionality appears to be captured in the v1.0/$metadata by the following declaration

<Action Name="copy" IsBound="true">
    <Parameter Name="bindingParameter" Type="microsoft.graph.driveItem" Nullable="false"/>
    <Parameter Name="name" Type="Edm.String" Unicode="false"/>
    <Parameter Name="parentReference" Type="microsoft.graph.itemReference"/>
    <ReturnType Type="microsoft.graph.driveItem" Nullable="false"/>
</Action>

And, at a glance, may be supported by classes related to DriveItemCopy

caitlinrussell commented 7 years ago

Validated that @diogowbrito 's code snippet works in the current version of the SDK.