{"action":"created","issue":{"url":"https://api.github.com/repos/OneDrive/onedrive-sdk-android/issues/108","repository_url":"https://api.github.com/repos/OneDrive/onedrive-sdk-android","labels_url":"https://api.github.com/repos/OneDrive/onedrive-sdk-android/issues/108/labels{/name}","comments_url":"https://api.github.com/repos/OneDrive/onedrive-sdk-android/issues/108/comments","events_url":"https://api.github.com/repos/OneDrive/onedrive-sdk-android/issues/108/events","html_url":"https://github.com/OneDrive/onedrive-sdk-android/issues/108","id":180561214,"number":108,"title":"OutOfMemory when uploading a huge file.","user":{"login":"isabsent","id":4918293,"avatar_url":"https://avatars.githubusercontent.com/u/4918293?v=3","gravatar_id":"","url":"https://api.github.com/users/isabsent","html_url":"https://github.com/isabsent","followers_url":"https://api.github.com/users/isabsent/followers","following_url":"https://api.github.com/users/isabsent/following{/other_user}","gists_url":"https://api.github.com/users/isabsent/gists{/gist_id}","starred_url":"https://api.github.com/users/isabsent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isabsent/subscriptions","organizations_url":"https://api.github.com/users/isabsent/orgs","repos_url":"https://api.github.com/users/isabsent/repos","events_url":"https://api.github.com/users/isabsent/events{/privacy}","received_events_url":"https://api.github.com/users/isabsent/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-03T04:28:05Z","updated_at":"2016-11-21T16:57:24Z","closed_at":null,"body":"I am trying to upload media file with size of 141 MB to OneDrive by means of your [code snippet:](https://github.com/OneDrive/onedrive-sdk-android/blob/master/docs/items.md#upload-a-file)\n\n```\nbyte[] fileInMemory = IOUtils.toByteArray(context.getContextResolver().openInputStream(Uri.fromFile(fileToUpload)));\nONE_DRIVE.getOneDrive().getService()\n        .getDrive()\n        .getItems(((OneDriveFile) parent).getId())\n        .getChildren()\n        .byId(getName())\n        .getContent()\n        .buildRequest()\n        .put(fileInMemory, callback);\n```\n\n(IOUtils is from org.apache.commons.io version 2.4) and get OOM error immediately:\n\n```\njava.lang.OutOfMemoryError: Failed to allocate a 147687689 byte allocation with 16777216 free bytes and 83MB until OOM\nat org.apache.commons.io.output.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:322)\nat org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:463)\n```\n\nHow about a [promised wrapper](https://github.com/OneDrive/onedrive-sdk-android/issues/13#issuecomment-161032289) on chunked upload? :)\n"},"comment":{"url":"https://api.github.com/repos/OneDrive/onedrive-sdk-android/issues/comments/261998086","html_url":"https://github.com/OneDrive/onedrive-sdk-android/issues/108#issuecomment-261998086","issue_url":"https://api.github.com/repos/OneDrive/onedrive-sdk-android/issues/108","id":261998086,"user":{"login":"daboxu","id":3971919,"avatar_url":"https://avatars.githubusercontent.com/u/3971919?v=3","gravatar_id":"","url":"https://api.github.com/users/daboxu","html_url":"https://github.com/daboxu","followers_url":"https://api.github.com/users/daboxu/followers","following_url":"https://api.github.com/users/daboxu/following{/other_user}","gists_url":"https://api.github.com/users/daboxu/gists{/gist_id}","starred_url":"https://api.github.com/users/daboxu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daboxu/subscriptions","organizations_url":"https://api.github.com/users/daboxu/orgs","repos_url":"https://api.github.com/users/daboxu/repos","events_url":"https://api.github.com/users/daboxu/events{/privacy}","received_events_url":"https://api.github.com/users/daboxu/received_events","type":"User","site_admin":false},"created_at":"2016-11-21T16:57:23Z","updated_at":"2016-11-21T16:57:23Z","body":"@isabsent here you go, I only applied callback pattern with synchronous case, curious how to apply async one? The operation is tightly combined with File IO and network so haven't found a good way to snitch into async way in the code. Any good ideas? The code I tested so far looks like:\r\n\r\n```java\r\n            final AsyncTask<Void, Void, Void> uploadFile = new AsyncTask<Void, Void, Void>() {\r\n                @Override\r\n                protected Void doInBackground(final Void... params) {\r\n                    try {\r\n                        final ContentResolver contentResolver = getActivity().getContentResolver();\r\n                        final ContentProviderClient contentProvider = contentResolver\r\n                                .acquireContentProviderClient(data.getData());\r\n                        contentProvider.release();\r\n\r\n                        final String filename = FileContent.getValidFileName(contentResolver, data.getData());\r\n                        final int fileSize = FileContent.getFileSize(contentProvider, data.getData());\r\n                        final InputStream fileStream = contentResolver.openInputStream(data.getData());\r\n                        final Option option = new QueryOption(\"@name.conflictBehavior\", \"fail\");\r\n\r\n                        oneDriveClient.getDrive()\r\n                                .getRoot()\r\n                                .getItemWithPath(<\"Path to file\">)\r\n                                .getCreateSession(new ChunkedUploadSessionDescriptor())\r\n                                .buildRequest()\r\n                                .post()\r\n                                .createUploadProvider(oneDriveClient, fileStream, fileSize, Item.class)\r\n                                .upload(Collections.singletonList(option),\r\n                                        new IProgressCallback<Item>() {\r\n                                            @Override\r\n                                            public void progress(long current, long max) {\r\n                                                dialog.setProgress((int) current);\r\n                                                dialog.setMax((int) max);\r\n\r\n                                            }\r\n\r\n                                            @Override\r\n                                            public void success(Item item) {dialog.dismiss();\r\n                                                Toast.makeText(getActivity(),\r\n                                                        application\r\n                                                                .getString(R.string.upload_complete,\r\n                                                                        item.name),\r\n                                                        Toast.LENGTH_LONG).show();\r\n                                                refresh();\r\n                                            }\r\n\r\n                                            @Override\r\n                                            public void failure(ClientException error) {\r\n                                                dialog.dismiss();\r\n                                                if (error.isError(OneDriveErrorCodes.NameAlreadyExists)) {\r\n                                                    Toast.makeText(getActivity(),\r\n                                                            R.string.upload_failed_name_conflict,\r\n                                                            Toast.LENGTH_LONG).show();\r\n                                                } else {\r\n                                                    Toast.makeText(getActivity(),\r\n                                                            application\r\n                                                                    .getString(R.string.upload_failed,\r\n                                                                            filename),\r\n                                                            Toast.LENGTH_LONG).show();\r\n                                                }\r\n                                            }\r\n                                        });\r\n                    } catch (final Exception e) {\r\n                        Log.e(getClass().getSimpleName(), e.getMessage());\r\n                        Log.e(getClass().getSimpleName(), e.toString());\r\n                    }\r\n                    return null;\r\n                }\r\n            };\r\n            uploadFile.execute();\r\n```"}}
{"actor":{"display_login":"daboxu"}}