Title: Unable to upload a file · Issue #472 · microsoftgraph/msgraph-sdk-java · GitHub
Open Graph Title: Unable to upload a file · Issue #472 · microsoftgraph/msgraph-sdk-java
X Title: Unable to upload a file · Issue #472 · microsoftgraph/msgraph-sdk-java
Description: I'm able to get the list of all files in a OneDrive folder and also download a file from a OneDrive Folder to my android device. But I am unable to upload a file to OneDrive. It silently crash when I call the post() function. I use MSAL ...
Open Graph Description: I'm able to get the list of all files in a OneDrive folder and also download a file from a OneDrive Folder to my android device. But I am unable to upload a file to OneDrive. It silently crash when...
X Description: I'm able to get the list of all files in a OneDrive folder and also download a file from a OneDrive Folder to my android device. But I am unable to upload a file to OneDrive. It silently crash ...
Opengraph URL: https://github.com/microsoftgraph/msgraph-sdk-java/issues/472
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unable to upload a file","articleBody":"I'm able to get the list of all files in a OneDrive folder and also download a file from a OneDrive Folder to my android device.\r\nBut I am unable to upload a file to OneDrive.\r\nIt silently crash when I call the post() function.\r\nI use MSAL to connect to OneDrive.\r\nMy scopes are: \"User.Read\", \"Files.ReadWrite.All\"\r\nI use microsoft-graph:2.0.0\r\n\r\nHere is a simplified code with minimal error handling inspired from the sample app found [here](https://docs.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=java):\r\n\r\nNote: I can debug step all the way to buildRequest() but it crashes when I try to step thru .post() \r\nThe requestUrl seams ok: `https://graph.microsoft.com/v1.0/me/drive/root:/TestFolder/Test File.sco:/microsoft.graph.createUploadSession`\r\n(Crashes at the line that is commented // ************* Silently craches here ***************** )\r\n\r\nThe runtime exception cause is: com.microsoft.graph.core.ClientException: Error during http request\r\n\r\n```\r\n private void oneDrive_UploadFile(final IAuthenticationResult authenticationResult, final String strLocalFilePath)\r\n {\r\n // Create a callback used by the upload provider\r\n IProgressCallback\u003cDriveItem> callback = new IProgressCallback\u003cDriveItem>()\r\n {\r\n @Override\r\n // Called after each slice of the file is uploaded\r\n public void progress(final long current, final long max)\r\n {\r\n System.out.println(\r\n String.format(\"Uploaded %d bytes of %d total bytes\", current, max)\r\n );\r\n }\r\n\r\n @Override\r\n public void success(final DriveItem result)\r\n {\r\n System.out.println(\r\n String.format(\"Uploaded file with ID: %s\", result.id)\r\n );\r\n executeOneDriveTask(authenticationResult);\r\n }\r\n\r\n public void failure(final ClientException ex)\r\n {\r\n System.out.println(\r\n String.format(\"Error uploading file: %s\", ex.getMessage())\r\n );\r\n }\r\n };\r\n\r\n // Get an input stream for the file\r\n File file = new File(strLocalFilePath);\r\n if (file.exists())\r\n {\r\n final String accessToken = authenticationResult.getAccessToken();\r\n\r\n IGraphServiceClient graphClient =\r\n GraphServiceClient\r\n .builder()\r\n .authenticationProvider(new IAuthenticationProvider()\r\n {\r\n @Override\r\n public void authenticateRequest(IHttpRequest request)\r\n {\r\n Log.d(TAG, \"Authenticating request,\" + request.getRequestUrl());\r\n request.addHeader(\"Authorization\", \"Bearer \" + accessToken);\r\n }\r\n })\r\n .buildClient();\r\n\r\n InputStream fileStream = null;\r\n try\r\n {\r\n fileStream = new FileInputStream(file);\r\n }\r\n catch (FileNotFoundException e)\r\n {\r\n e.printStackTrace();\r\n }\r\n long streamSize = file.length();\r\n\r\n // Create an upload session\r\n UploadSession uploadSession = graphClient\r\n .me()\r\n .drive()\r\n .root()\r\n // itemPath like \"/Folder/file.txt\"\r\n // does not need to be a path to an existing item\r\n .itemWithPath(AppPrefs.getInstance().getOneDriveFolder() + '/' + file.getName())\r\n .createUploadSession(new DriveItemUploadableProperties())\r\n .buildRequest()\r\n .post(); // ************* Silently craches here ***************** \r\n\r\n ChunkedUploadProvider\u003cDriveItem> chunkedUploadProvider = new ChunkedUploadProvider\u003cDriveItem>(\r\n uploadSession,\r\n graphClient,\r\n fileStream,\r\n streamSize,\r\n DriveItem.class);\r\n\r\n // Config parameter is an array of integers\r\n // customConfig[0] indicates the max slice size\r\n // Max slice size must be a multiple of 320 KiB\r\n int[] customConfig = {2 * 320 * 1024};\r\n\r\n // Do the upload\r\n try\r\n {\r\n chunkedUploadProvider.upload(callback, customConfig);\r\n }\r\n catch (IOException e)\r\n {\r\n e.printStackTrace();\r\n }\r\n }\r\n }\r\n\r\n```\r\n\r\nAny clue ?\r\n\r\n\r\nThanks","author":{"url":"https://github.com/RegisStGelais","@type":"Person","name":"RegisStGelais"},"datePublished":"2020-09-15T17:52:17Z","url":"https://github.com/microsoftgraph/msgraph-sdk-java/issues/472"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1794d69e-b49d-e5dd-75fc-56a574404b9a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D942:226126:E0EA9D:12B066C:6B050D10 |
| html-safe-nonce | 17c63dcf7856467c169cce3cec7bd961878938413ce5164cdcea9c5d9788a711 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTQyOjIyNjEyNjpFMEVBOUQ6MTJCMDY2Qzo2QjA1MEQxMCIsInZpc2l0b3JfaWQiOiIyMTI0NDk1NjQwNTAyNTM3NDg5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 094523dec1f945d7ae0e46d77f50df2c5c4e073a87ff513b456b66189748496b |
| hovercard-subject-tag | issue:702133129 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoftgraph/msgraph-sdk-java/472/issue_layout |
| twitter:image | https://opengraph.githubassets.com/634b7d8e38b0cefd223bfc23871481e48c65a9d9023ad3e4508b1603084ea12d/microsoftgraph/msgraph-sdk-java/issues/472 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/634b7d8e38b0cefd223bfc23871481e48c65a9d9023ad3e4508b1603084ea12d/microsoftgraph/msgraph-sdk-java/issues/472 |
| og:image:alt | I'm able to get the list of all files in a OneDrive folder and also download a file from a OneDrive Folder to my android device. But I am unable to upload a file to OneDrive. It silently crash when... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RegisStGelais |
| hostname | github.com |
| expected-hostname | github.com |
| None | 854d880890b5e847b3fce9d1b31f032107baeddeebad2aa379c48aa4f1451f6b |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoftgraph/msgraph-sdk-java git https://github.com/microsoftgraph/msgraph-sdk-java.git |
| octolytics-dimension-user_id | 17304259 |
| octolytics-dimension-user_login | microsoftgraph |
| octolytics-dimension-repository_id | 103300409 |
| octolytics-dimension-repository_nwo | microsoftgraph/msgraph-sdk-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 103300409 |
| octolytics-dimension-repository_network_root_nwo | microsoftgraph/msgraph-sdk-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 220e980097d94ce616d5d11fbd5316d208e3fc93 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width