{"action":"created","comment":{"url":"https://api.github.com/repos/zulip/zulip/pulls/comments/60673038","id":60673038,"diff_hunk":"@@ -195,9 +211,24 @@ def upload_message_image_local(uploaded_file_name, content_type, file_data, user\n     ])\n \n     write_local_file('files', path, file_data)\n-\n+    store_as_temp(uploaded_file_name, path, user_profile)\n     return '/user_uploads/' + path\n \n+\n+def store_as_temp(file_name, path_id, user_profile):\n+    Attachment.objects.create(file_name=file_name, path_id=path_id, owner=user_profile)\n+    return True\n+\n+def delete_message_image_local(path_id):\n+    file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, 'files', path_id)\n+    #check if file exists","path":"zerver/lib/upload.py","position":52,"original_position":52,"commit_id":"c4a8caea4419017d248dc9b379f60eebcda2e73c","original_commit_id":"c4a8caea4419017d248dc9b379f60eebcda2e73c","user":{"login":"timabbott","id":2746074,"avatar_url":"https://avatars.githubusercontent.com/u/2746074?v=3","gravatar_id":"","url":"https://api.github.com/users/timabbott","html_url":"https://github.com/timabbott","followers_url":"https://api.github.com/users/timabbott/followers","following_url":"https://api.github.com/users/timabbott/following{/other_user}","gists_url":"https://api.github.com/users/timabbott/gists{/gist_id}","starred_url":"https://api.github.com/users/timabbott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timabbott/subscriptions","organizations_url":"https://api.github.com/users/timabbott/orgs","repos_url":"https://api.github.com/users/timabbott/repos","events_url":"https://api.github.com/users/timabbott/events{/privacy}","received_events_url":"https://api.github.com/users/timabbott/received_events","type":"User","site_admin":false},"body":"delete this comment; it's clear from the code what it's doing","created_at":"2016-04-21T23:50:35Z","updated_at":"2016-04-21T23:50:35Z","html_url":"https://github.com/zulip/zulip/pull/584#discussion_r60673038","pull_request_url":"https://api.github.com/repos/zulip/zulip/pulls/584","_links":{"self":{"href":"https://api.github.com/repos/zulip/zulip/pulls/comments/60673038"},"html":{"href":"https://github.com/zulip/zulip/pull/584#discussion_r60673038"},"pull_request":{"href":"https://api.github.com/repos/zulip/zulip/pulls/584"}}},"pull_request":{"url":"https://api.github.com/repos/zulip/zulip/pulls/584","id":64089960,"html_url":"https://github.com/zulip/zulip/pull/584","diff_url":"https://github.com/zulip/zulip/pull/584.diff","patch_url":"https://github.com/zulip/zulip/pull/584.patch","issue_url":"https://api.github.com/repos/zulip/zulip/issues/584","number":584,"state":"open","locked":false,"title":"Temporarily store attachments till message is recieved","user":{"login":"rahuldeve","id":4870175,"avatar_url":"https://avatars.githubusercontent.com/u/4870175?v=3","gravatar_id":"","url":"https://api.github.com/users/rahuldeve","html_url":"https://github.com/rahuldeve","followers_url":"https://api.github.com/users/rahuldeve/followers","following_url":"https://api.github.com/users/rahuldeve/following{/other_user}","gists_url":"https://api.github.com/users/rahuldeve/gists{/gist_id}","starred_url":"https://api.github.com/users/rahuldeve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rahuldeve/subscriptions","organizations_url":"https://api.github.com/users/rahuldeve/orgs","repos_url":"https://api.github.com/users/rahuldeve/repos","events_url":"https://api.github.com/users/rahuldeve/events{/privacy}","received_events_url":"https://api.github.com/users/rahuldeve/received_events","type":"User","site_admin":false},"body":"Currently zulip stores attachments without actually checking if they are being referenced in the message being sent(the sender can just remove the upload string after the upload). This will just leave an orphaned file in the storage and will cause problems when trying to implement issue #454 \r\n\r\nI have made it store the attachment as a temp file in /tmp till it receives a message having the upload string in its body. For now it works only for local storage and not for S3. ","created_at":"2016-03-24T19:58:26Z","updated_at":"2016-04-21T23:50:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ab7859af4a23e9d68e8f0f5dd3045ca4d4602b8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zulip/zulip/pulls/584/commits","review_comments_url":"https://api.github.com/repos/zulip/zulip/pulls/584/comments","review_comment_url":"https://api.github.com/repos/zulip/zulip/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zulip/zulip/issues/584/comments","statuses_url":"https://api.github.com/repos/zulip/zulip/statuses/c4a8caea4419017d248dc9b379f60eebcda2e73c","head":{"label":"rahuldeve:temp-file","ref":"temp-file","sha":"c4a8caea4419017d248dc9b379f60eebcda2e73c","user":{"login":"rahuldeve","id":4870175,"avatar_url":"https://avatars.githubusercontent.com/u/4870175?v=3","gravatar_id":"","url":"https://api.github.com/users/rahuldeve","html_url":"https://github.com/rahuldeve","followers_url":"https://api.github.com/users/rahuldeve/followers","following_url":"https://api.github.com/users/rahuldeve/following{/other_user}","gists_url":"https://api.github.com/users/rahuldeve/gists{/gist_id}","starred_url":"https://api.github.com/users/rahuldeve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rahuldeve/subscriptions","organizations_url":"https://api.github.com/users/rahuldeve/orgs","repos_url":"https://api.github.com/users/rahuldeve/repos","events_url":"https://api.github.com/users/rahuldeve/events{/privacy}","received_events_url":"https://api.github.com/users/rahuldeve/received_events","type":"User","site_admin":false},"repo":{"id":54367885,"name":"zulip","full_name":"rahuldeve/zulip","owner":{"login":"rahuldeve","id":4870175,"avatar_url":"https://avatars.githubusercontent.com/u/4870175?v=3","gravatar_id":"","url":"https://api.github.com/users/rahuldeve","html_url":"https://github.com/rahuldeve","followers_url":"https://api.github.com/users/rahuldeve/followers","following_url":"https://api.github.com/users/rahuldeve/following{/other_user}","gists_url":"https://api.github.com/users/rahuldeve/gists{/gist_id}","starred_url":"https://api.github.com/users/rahuldeve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rahuldeve/subscriptions","organizations_url":"https://api.github.com/users/rahuldeve/orgs","repos_url":"https://api.github.com/users/rahuldeve/repos","events_url":"https://api.github.com/users/rahuldeve/events{/privacy}","received_events_url":"https://api.github.com/users/rahuldeve/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rahuldeve/zulip","description":"Zulip server - powerful open source group chat","fork":true,"url":"https://api.github.com/repos/rahuldeve/zulip","forks_url":"https://api.github.com/repos/rahuldeve/zulip/forks","keys_url":"https://api.github.com/repos/rahuldeve/zulip/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rahuldeve/zulip/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rahuldeve/zulip/teams","hooks_url":"https://api.github.com/repos/rahuldeve/zulip/hooks","issue_events_url":"https://api.github.com/repos/rahuldeve/zulip/issues/events{/number}","events_url":"https://api.github.com/repos/rahuldeve/zulip/events","assignees_url":"https://api.github.com/repos/rahuldeve/zulip/assignees{/user}","branches_url":"https://api.github.com/repos/rahuldeve/zulip/branches{/branch}","tags_url":"https://api.github.com/repos/rahuldeve/zulip/tags","blobs_url":"https://api.github.com/repos/rahuldeve/zulip/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rahuldeve/zulip/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rahuldeve/zulip/git/refs{/sha}","trees_url":"https://api.github.com/repos/rahuldeve/zulip/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rahuldeve/zulip/statuses/{sha}","languages_url":"https://api.github.com/repos/rahuldeve/zulip/languages","stargazers_url":"https://api.github.com/repos/rahuldeve/zulip/stargazers","contributors_url":"https://api.github.com/repos/rahuldeve/zulip/contributors","subscribers_url":"https://api.github.com/repos/rahuldeve/zulip/subscribers","subscription_url":"https://api.github.com/repos/rahuldeve/zulip/subscription","commits_url":"https://api.github.com/repos/rahuldeve/zulip/commits{/sha}","git_commits_url":"https://api.github.com/repos/rahuldeve/zulip/git/commits{/sha}","comments_url":"https://api.github.com/repos/rahuldeve/zulip/comments{/number}","issue_comment_url":"https://api.github.com/repos/rahuldeve/zulip/issues/comments{/number}","contents_url":"https://api.github.com/repos/rahuldeve/zulip/contents/{+path}","compare_url":"https://api.github.com/repos/rahuldeve/zulip/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rahuldeve/zulip/merges","archive_url":"https://api.github.com/repos/rahuldeve/zulip/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rahuldeve/zulip/downloads","issues_url":"https://api.github.com/repos/rahuldeve/zulip/issues{/number}","pulls_url":"https://api.github.com/repos/rahuldeve/zulip/pulls{/number}","milestones_url":"https://api.github.com/repos/rahuldeve/zulip/milestones{/number}","notifications_url":"https://api.github.com/repos/rahuldeve/zulip/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rahuldeve/zulip/labels{/name}","releases_url":"https://api.github.com/repos/rahuldeve/zulip/releases{/id}","deployments_url":"https://api.github.com/repos/rahuldeve/zulip/deployments","created_at":"2016-03-21T07:22:04Z","updated_at":"2016-03-21T07:22:11Z","pushed_at":"2016-04-21T17:00:42Z","git_url":"git://github.com/rahuldeve/zulip.git","ssh_url":"git@github.com:rahuldeve/zulip.git","clone_url":"https://github.com/rahuldeve/zulip.git","svn_url":"https://github.com/rahuldeve/zulip","homepage":"","size":107428,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"zulip:master","ref":"master","sha":"d9dba5d2c25ed6e2ff9e409368fcc01c2de2f1cb","user":{"login":"zulip","id":4921959,"avatar_url":"https://avatars.githubusercontent.com/u/4921959?v=3","gravatar_id":"","url":"https://api.github.com/users/zulip","html_url":"https://github.com/zulip","followers_url":"https://api.github.com/users/zulip/followers","following_url":"https://api.github.com/users/zulip/following{/other_user}","gists_url":"https://api.github.com/users/zulip/gists{/gist_id}","starred_url":"https://api.github.com/users/zulip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zulip/subscriptions","organizations_url":"https://api.github.com/users/zulip/orgs","repos_url":"https://api.github.com/users/zulip/repos","events_url":"https://api.github.com/users/zulip/events{/privacy}","received_events_url":"https://api.github.com/users/zulip/received_events","type":"Organization","site_admin":false},"repo":{"id":43160685,"name":"zulip","full_name":"zulip/zulip","owner":{"login":"zulip","id":4921959,"avatar_url":"https://avatars.githubusercontent.com/u/4921959?v=3","gravatar_id":"","url":"https://api.github.com/users/zulip","html_url":"https://github.com/zulip","followers_url":"https://api.github.com/users/zulip/followers","following_url":"https://api.github.com/users/zulip/following{/other_user}","gists_url":"https://api.github.com/users/zulip/gists{/gist_id}","starred_url":"https://api.github.com/users/zulip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zulip/subscriptions","organizations_url":"https://api.github.com/users/zulip/orgs","repos_url":"https://api.github.com/users/zulip/repos","events_url":"https://api.github.com/users/zulip/events{/privacy}","received_events_url":"https://api.github.com/users/zulip/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zulip/zulip","description":"Zulip server - powerful open source group chat","fork":false,"url":"https://api.github.com/repos/zulip/zulip","forks_url":"https://api.github.com/repos/zulip/zulip/forks","keys_url":"https://api.github.com/repos/zulip/zulip/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zulip/zulip/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zulip/zulip/teams","hooks_url":"https://api.github.com/repos/zulip/zulip/hooks","issue_events_url":"https://api.github.com/repos/zulip/zulip/issues/events{/number}","events_url":"https://api.github.com/repos/zulip/zulip/events","assignees_url":"https://api.github.com/repos/zulip/zulip/assignees{/user}","branches_url":"https://api.github.com/repos/zulip/zulip/branches{/branch}","tags_url":"https://api.github.com/repos/zulip/zulip/tags","blobs_url":"https://api.github.com/repos/zulip/zulip/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zulip/zulip/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zulip/zulip/git/refs{/sha}","trees_url":"https://api.github.com/repos/zulip/zulip/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zulip/zulip/statuses/{sha}","languages_url":"https://api.github.com/repos/zulip/zulip/languages","stargazers_url":"https://api.github.com/repos/zulip/zulip/stargazers","contributors_url":"https://api.github.com/repos/zulip/zulip/contributors","subscribers_url":"https://api.github.com/repos/zulip/zulip/subscribers","subscription_url":"https://api.github.com/repos/zulip/zulip/subscription","commits_url":"https://api.github.com/repos/zulip/zulip/commits{/sha}","git_commits_url":"https://api.github.com/repos/zulip/zulip/git/commits{/sha}","comments_url":"https://api.github.com/repos/zulip/zulip/comments{/number}","issue_comment_url":"https://api.github.com/repos/zulip/zulip/issues/comments{/number}","contents_url":"https://api.github.com/repos/zulip/zulip/contents/{+path}","compare_url":"https://api.github.com/repos/zulip/zulip/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zulip/zulip/merges","archive_url":"https://api.github.com/repos/zulip/zulip/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zulip/zulip/downloads","issues_url":"https://api.github.com/repos/zulip/zulip/issues{/number}","pulls_url":"https://api.github.com/repos/zulip/zulip/pulls{/number}","milestones_url":"https://api.github.com/repos/zulip/zulip/milestones{/number}","notifications_url":"https://api.github.com/repos/zulip/zulip/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zulip/zulip/labels{/name}","releases_url":"https://api.github.com/repos/zulip/zulip/releases{/id}","deployments_url":"https://api.github.com/repos/zulip/zulip/deployments","created_at":"2015-09-25T16:37:25Z","updated_at":"2016-04-21T00:16:22Z","pushed_at":"2016-04-21T23:04:44Z","git_url":"git://github.com/zulip/zulip.git","ssh_url":"git@github.com:zulip/zulip.git","clone_url":"https://github.com/zulip/zulip.git","svn_url":"https://github.com/zulip/zulip","homepage":"","size":112848,"stargazers_count":3816,"watchers_count":3816,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":530,"mirror_url":null,"open_issues_count":251,"forks":530,"open_issues":251,"watchers":3816,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zulip/zulip/pulls/584"},"html":{"href":"https://github.com/zulip/zulip/pull/584"},"issue":{"href":"https://api.github.com/repos/zulip/zulip/issues/584"},"comments":{"href":"https://api.github.com/repos/zulip/zulip/issues/584/comments"},"review_comments":{"href":"https://api.github.com/repos/zulip/zulip/pulls/584/comments"},"review_comment":{"href":"https://api.github.com/repos/zulip/zulip/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zulip/zulip/pulls/584/commits"},"statuses":{"href":"https://api.github.com/repos/zulip/zulip/statuses/c4a8caea4419017d248dc9b379f60eebcda2e73c"}}}}