{"action":"created","comment":{"url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/comments/63306020","id":63306020,"diff_hunk":"@@ -0,0 +1,88 @@\n+package com.pdffiller.client.utils;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.math.BigInteger;\n+import java.nio.file.Files;\n+import java.security.SecureRandom;\n+import java.util.HashMap;\n+\n+public class MultipartHelper {\n+  private static final String CRLF = \"\\r\\n\";\n+  private File file;\n+  private String boundary;\n+  private byte[] message;\n+\n+  public File getFile() {\n+    return file;\n+  }\n+\n+  public void setFile(File file) {\n+    this.file = file;\n+  }\n+\n+  public byte[] getMessage() {\n+    return message;\n+  }\n+\n+  public MultipartHelper(String file) {\n+    this.file = new File(file);\n+    boundary = generateBoundary();\n+    message = formRequest();\n+  }\n+\n+  private String generateBoundary() {\n+    SecureRandom random = new SecureRandom();\n+    return new BigInteger(20, random).toString();\n+  }\n+\n+  private String getMime() {\n+    String mime = null;\n+    try {\n+      mime = Files.probeContentType(file.toPath());\n+    } catch (IOException e) {\n+      e.printStackTrace();\n+    }\n+\n+    return mime;\n+  }\n+\n+  public byte[] getFileContent() {\n+    byte[] content = new byte[0];\n+    try {\n+      content = Files.readAllBytes(file.toPath());\n+    } catch (IOException e) {\n+      e.printStackTrace();\n+    }\n+    return content;\n+  }\n+\n+  public byte[] formRequest() {\n+    String message1 = \"--\" + boundary + CRLF;\n+\n+    message1 += \"Content-Disposition: form-data; name=\\\"file\\\";\" +","path":"src/main/java/com/pdffiller/client/utils/MultipartHelper.java","position":63,"original_position":63,"commit_id":"83cd9a5e8dd2f1fd900d2c89173e6d98c72de05c","original_commit_id":"83cd9a5e8dd2f1fd900d2c89173e6d98c72de05c","user":{"login":"egorelik","id":1163933,"avatar_url":"https://avatars.githubusercontent.com/u/1163933?v=3","gravatar_id":"","url":"https://api.github.com/users/egorelik","html_url":"https://github.com/egorelik","followers_url":"https://api.github.com/users/egorelik/followers","following_url":"https://api.github.com/users/egorelik/following{/other_user}","gists_url":"https://api.github.com/users/egorelik/gists{/gist_id}","starred_url":"https://api.github.com/users/egorelik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/egorelik/subscriptions","organizations_url":"https://api.github.com/users/egorelik/orgs","repos_url":"https://api.github.com/users/egorelik/repos","events_url":"https://api.github.com/users/egorelik/events{/privacy}","received_events_url":"https://api.github.com/users/egorelik/received_events","type":"User","site_admin":false},"body":"What is a \"message1\" , \"content\" and \"message2\"?\r\n\r\nLet's call it messageHeader, messageContent and messageBoundary. \r\nRemember, this code will be read publicly.\r\n\r\nI recommend using StringBuilder instead of concatenation + \r\n\r\nStringBuilder sb = new StringBuilder();\r\nstr = sb.append(str1).append(str2).append(str3)\r\n\r\n+ creates new object every time it is used. Modern Java compilers convert + to StringBuilder on the background\r\n \r\n\r\n","created_at":"2016-05-16T03:01:01Z","updated_at":"2016-05-16T03:01:01Z","html_url":"https://github.com/pdffiller/pdffiller-java-api-client/pull/4#discussion_r63306020","pull_request_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/comments/63306020"},"html":{"href":"https://github.com/pdffiller/pdffiller-java-api-client/pull/4#discussion_r63306020"},"pull_request":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/4","id":69990690,"html_url":"https://github.com/pdffiller/pdffiller-java-api-client/pull/4","diff_url":"https://github.com/pdffiller/pdffiller-java-api-client/pull/4.diff","patch_url":"https://github.com/pdffiller/pdffiller-java-api-client/pull/4.patch","issue_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues/4","number":4,"state":"open","locked":false,"title":"KSV | API-289 | Added multipart document upload","user":{"login":"srgkas","id":17566364,"avatar_url":"https://avatars.githubusercontent.com/u/17566364?v=3","gravatar_id":"","url":"https://api.github.com/users/srgkas","html_url":"https://github.com/srgkas","followers_url":"https://api.github.com/users/srgkas/followers","following_url":"https://api.github.com/users/srgkas/following{/other_user}","gists_url":"https://api.github.com/users/srgkas/gists{/gist_id}","starred_url":"https://api.github.com/users/srgkas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srgkas/subscriptions","organizations_url":"https://api.github.com/users/srgkas/orgs","repos_url":"https://api.github.com/users/srgkas/repos","events_url":"https://api.github.com/users/srgkas/events{/privacy}","received_events_url":"https://api.github.com/users/srgkas/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-13T12:51:58Z","updated_at":"2016-05-16T03:01:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"abf5e0fe518622029e98493b501ae3534122b7a4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/4/commits","review_comments_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/4/comments","review_comment_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues/4/comments","statuses_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/statuses/83cd9a5e8dd2f1fd900d2c89173e6d98c72de05c","head":{"label":"pdffiller:feature-ksv-api_289-multipart_file_upload","ref":"feature-ksv-api_289-multipart_file_upload","sha":"83cd9a5e8dd2f1fd900d2c89173e6d98c72de05c","user":{"login":"pdffiller","id":17018358,"avatar_url":"https://avatars.githubusercontent.com/u/17018358?v=3","gravatar_id":"","url":"https://api.github.com/users/pdffiller","html_url":"https://github.com/pdffiller","followers_url":"https://api.github.com/users/pdffiller/followers","following_url":"https://api.github.com/users/pdffiller/following{/other_user}","gists_url":"https://api.github.com/users/pdffiller/gists{/gist_id}","starred_url":"https://api.github.com/users/pdffiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdffiller/subscriptions","organizations_url":"https://api.github.com/users/pdffiller/orgs","repos_url":"https://api.github.com/users/pdffiller/repos","events_url":"https://api.github.com/users/pdffiller/events{/privacy}","received_events_url":"https://api.github.com/users/pdffiller/received_events","type":"Organization","site_admin":false},"repo":{"id":53978694,"name":"pdffiller-java-api-client","full_name":"pdffiller/pdffiller-java-api-client","owner":{"login":"pdffiller","id":17018358,"avatar_url":"https://avatars.githubusercontent.com/u/17018358?v=3","gravatar_id":"","url":"https://api.github.com/users/pdffiller","html_url":"https://github.com/pdffiller","followers_url":"https://api.github.com/users/pdffiller/followers","following_url":"https://api.github.com/users/pdffiller/following{/other_user}","gists_url":"https://api.github.com/users/pdffiller/gists{/gist_id}","starred_url":"https://api.github.com/users/pdffiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdffiller/subscriptions","organizations_url":"https://api.github.com/users/pdffiller/orgs","repos_url":"https://api.github.com/users/pdffiller/repos","events_url":"https://api.github.com/users/pdffiller/events{/privacy}","received_events_url":"https://api.github.com/users/pdffiller/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pdffiller/pdffiller-java-api-client","description":"PDFfiller Java API Client","fork":false,"url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client","forks_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/forks","keys_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/teams","hooks_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/hooks","issue_events_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues/events{/number}","events_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/events","assignees_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/assignees{/user}","branches_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/branches{/branch}","tags_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/tags","blobs_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/statuses/{sha}","languages_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/languages","stargazers_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/stargazers","contributors_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/contributors","subscribers_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/subscribers","subscription_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/subscription","commits_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/contents/{+path}","compare_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/merges","archive_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/downloads","issues_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues{/number}","pulls_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls{/number}","milestones_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/milestones{/number}","notifications_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/labels{/name}","releases_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/releases{/id}","deployments_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/deployments","created_at":"2016-03-15T21:09:49Z","updated_at":"2016-03-15T21:14:31Z","pushed_at":"2016-05-13T12:51:58Z","git_url":"git://github.com/pdffiller/pdffiller-java-api-client.git","ssh_url":"git@github.com:pdffiller/pdffiller-java-api-client.git","clone_url":"https://github.com/pdffiller/pdffiller-java-api-client.git","svn_url":"https://github.com/pdffiller/pdffiller-java-api-client","homepage":null,"size":41,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"v1.0"}},"base":{"label":"pdffiller:v1.0","ref":"v1.0","sha":"f5b44d0e72ffb0ed1b654414a7f53a0a0a52f834","user":{"login":"pdffiller","id":17018358,"avatar_url":"https://avatars.githubusercontent.com/u/17018358?v=3","gravatar_id":"","url":"https://api.github.com/users/pdffiller","html_url":"https://github.com/pdffiller","followers_url":"https://api.github.com/users/pdffiller/followers","following_url":"https://api.github.com/users/pdffiller/following{/other_user}","gists_url":"https://api.github.com/users/pdffiller/gists{/gist_id}","starred_url":"https://api.github.com/users/pdffiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdffiller/subscriptions","organizations_url":"https://api.github.com/users/pdffiller/orgs","repos_url":"https://api.github.com/users/pdffiller/repos","events_url":"https://api.github.com/users/pdffiller/events{/privacy}","received_events_url":"https://api.github.com/users/pdffiller/received_events","type":"Organization","site_admin":false},"repo":{"id":53978694,"name":"pdffiller-java-api-client","full_name":"pdffiller/pdffiller-java-api-client","owner":{"login":"pdffiller","id":17018358,"avatar_url":"https://avatars.githubusercontent.com/u/17018358?v=3","gravatar_id":"","url":"https://api.github.com/users/pdffiller","html_url":"https://github.com/pdffiller","followers_url":"https://api.github.com/users/pdffiller/followers","following_url":"https://api.github.com/users/pdffiller/following{/other_user}","gists_url":"https://api.github.com/users/pdffiller/gists{/gist_id}","starred_url":"https://api.github.com/users/pdffiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdffiller/subscriptions","organizations_url":"https://api.github.com/users/pdffiller/orgs","repos_url":"https://api.github.com/users/pdffiller/repos","events_url":"https://api.github.com/users/pdffiller/events{/privacy}","received_events_url":"https://api.github.com/users/pdffiller/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pdffiller/pdffiller-java-api-client","description":"PDFfiller Java API Client","fork":false,"url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client","forks_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/forks","keys_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/teams","hooks_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/hooks","issue_events_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues/events{/number}","events_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/events","assignees_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/assignees{/user}","branches_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/branches{/branch}","tags_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/tags","blobs_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/statuses/{sha}","languages_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/languages","stargazers_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/stargazers","contributors_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/contributors","subscribers_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/subscribers","subscription_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/subscription","commits_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/contents/{+path}","compare_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/merges","archive_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/downloads","issues_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues{/number}","pulls_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls{/number}","milestones_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/milestones{/number}","notifications_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/labels{/name}","releases_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/releases{/id}","deployments_url":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/deployments","created_at":"2016-03-15T21:09:49Z","updated_at":"2016-03-15T21:14:31Z","pushed_at":"2016-05-13T12:51:58Z","git_url":"git://github.com/pdffiller/pdffiller-java-api-client.git","ssh_url":"git@github.com:pdffiller/pdffiller-java-api-client.git","clone_url":"https://github.com/pdffiller/pdffiller-java-api-client.git","svn_url":"https://github.com/pdffiller/pdffiller-java-api-client","homepage":null,"size":41,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"v1.0"}},"_links":{"self":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/4"},"html":{"href":"https://github.com/pdffiller/pdffiller-java-api-client/pull/4"},"issue":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues/4"},"comments":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/pdffiller/pdffiller-java-api-client/statuses/83cd9a5e8dd2f1fd900d2c89173e6d98c72de05c"}}}}