KoenZomers / OneDriveAPI

API in .NET Framework 4.8.0, .NET Core 3.1 and .NET 6.0 to communicate with OneDrive Personal and OneDrive for Business
Eclipse Public License 1.0
110 stars 35 forks source link

Download File #9

Closed BurhanEyimaya closed 6 years ago

BurhanEyimaya commented 6 years ago

Hi,

Thank you for this great API.

But I have an issue on downloading files from OneDrive. In your demo application I tried to upload a single file "Test.txt" to folder "Test\sub1\sub". Upload completed with success.

But the download operation fails. In error message it says "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

capture

Thanks, Burhan Eyimaya

KoenZomers commented 6 years ago

Hi Burhan,

Is there no inner exception with more information? Are you using a proxy? Can you capture a Fiddler trace while doing the download and see what's really happening on the wire? If you need help examining it, mail it to me privately as it will contain your refresh token which you should not publish publicly.

BurhanEyimaya commented 6 years ago

Hi Koen, Thank you for your fast response. Here is the full exception details TYPE : System.Net.Http.HttpRequestException MESSAGE: An error occurred while sending the request. STACK TRACE: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at KoenZomers.OneDrive.Api.OneDriveApi.<DownloadItemInternal>d__106.MoveNext() in D:\Projects\MS\OneDriveAPI\Api\OneDriveApi.cs:line 1010 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at KoenZomers.OneDrive.Api.OneDriveApi.d89.MoveNext() in D:\Projects\MS\OneDriveAPI\Api\OneDriveApi.cs:line 701 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at KoenZomers.OneDrive.Api.OneDriveApi.d87.MoveNext() in D:\Projects\MS\OneDriveAPI\Api\OneDriveApi.cs:line 675 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at AuthenticatorApp.MainForm.d__25.MoveNext() in D:\Projects\MS\OneDriveAPI\Demo\MainForm.cs:line 337 ---- inner exception ---------------------------------------- TYPE : System.Net.WebException MESSAGE: The underlying connection was closed: An unexpected error occurred on a send. STACK TRACE: at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) ---- inner exception ---------------------------------------- TYPE : System.IO.IOException MESSAGE: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. STACK TRACE: at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) ---- inner exception ---------------------------------------- TYPE : System.Net.Sockets.SocketException MESSAGE: An existing connection was forcibly closed by the remote host STACK TRACE: at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) Also I have attached the Fiddler session file. I think there is no traffic during the download. Sorry I couldn't understand the problem. Thanks, Burhan Eyimaya

Sent from Outlookhttp://aka.ms/weboutlook


From: Koen Zomers notifications@github.com Sent: Thursday, December 21, 2017 20:33 To: KoenZomers/OneDriveAPI Cc: Burhan Eyimaya; Author Subject: Re: [KoenZomers/OneDriveAPI] Download File (#9)

Hi Burhan,

Is there no inner exception with more information? Are you using a proxy? Can you capture a Fiddler trace while doing the download and see what's really happening on the wire? If you need help examining it, mail it to me privately as it will contain your refresh token which you should not publish publicly.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/KoenZomers/OneDriveAPI/issues/9#issuecomment-353410488, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AHNzqkpPa3w7h8xqBNFGDAw7qNC_-iX-ks5tCpZWgaJpZM4RJ1_L.

BurhanEyimaya commented 6 years ago

Hi,

Also I have tried to upload to the Apps folder. OneDriveApi.UploadFileToAppFolder("Save.sav"); This works and uploads the "Save.sav" file to Apps folder.

But download fails.

OneDriveItemCollection oneDriveItems = await OneDriveApi.GetAppFolderChildren();
OneDriveItem oneDriveItem = oneDriveItems.Collection.Where(x => x.Name == "Save.sav").SingleOrDefault();
await OneDriveApi.DownloadItem(oneDriveItem, downloadDir);

Here oneDriveItems collection and oneDriveItem variables are valid so it can find the correct files, but download fails. Could you please try to download a file from Apps folder?

Thanks, Burhan Eyimaya

KoenZomers commented 6 years ago

Hi Burhan,

Downloading works fine here. I modified the demo application at the following lines to mimic your scenario:

[cid:image001.png@01D381C7.84745D90] This works well and it nicely stores the LICENSE.md file I have in the App Folder on my OneDrive for Business: [cid:image002.png@01D381C7.84745D90] To my D: drive: [cid:image003.png@01D381C7.84745D90] The Fiddler trace you shared just contains the authentication part. It doesn’t show even attempting any operation after connecting.

The error indicates something is blocking your network traffic on your machine. Could there be a proxy, firewall or anti virus product on your machine blocking this traffic? Try it from another machine on another internet line.

Kind regards,

Koen

From: Burhan Eyimaya [mailto:notifications@github.com] Sent: vrijdag 22 december 2017 13:41 To: KoenZomers/OneDriveAPI OneDriveAPI@noreply.github.com Cc: Koen Zomers koen@zomers.eu; Comment comment@noreply.github.com Subject: Re: [KoenZomers/OneDriveAPI] Download File (#9)

Hi,

Also I have tried to upload Apps folder. OneDriveApi.UploadFileToAppFolder("Save.sav"); This works and uploads the "Save.sav" file to Apps folder.

But download fails.

OneDriveItemCollection oneDriveItems = await OneDriveApi.GetAppFolderChildren(); OneDriveItem oneDriveItem = oneDriveItems.Collection.Where(x => x.Name == "Save.sav").SingleOrDefault(); await OneDriveApi.DownloadItem(oneDriveItem, downloadDir);

Could you please try to download a file from Apps folder?

Thanks, Burhan Eyimaya

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/KoenZomers/OneDriveAPI/issues/9#issuecomment-353590945, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFqlvtgBWWRwljC-HEkvRVd-YSp5s4liks5tC6NYgaJpZM4RJ1_L.

KoenZomers commented 6 years ago

@BurhanEyimaya any luck in getting it to work?

BurhanEyimaya commented 6 years ago

Hi Koen,

Thank you for your attention. Yes it worked. You are right it was a problem related to my network. Thanks again, and sorry for this false warning.

KoenZomers commented 6 years ago

@BurhanEyimaya good to hear it's resolved. Thanks for confirming!