{"action":"created","issue":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1742","repository_url":"https://api.github.com/repos/Alamofire/Alamofire","labels_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1742/labels{/name}","comments_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1742/comments","events_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1742/events","html_url":"https://github.com/Alamofire/Alamofire/issues/1742","id":186170395,"number":1742,"title":"Alamofire.upload with Multipart Form Data isn't removing temporary files after the request finished","user":{"login":"ricardopereira","id":3541185,"avatar_url":"https://avatars.githubusercontent.com/u/3541185?v=3","gravatar_id":"","url":"https://api.github.com/users/ricardopereira","html_url":"https://github.com/ricardopereira","followers_url":"https://api.github.com/users/ricardopereira/followers","following_url":"https://api.github.com/users/ricardopereira/following{/other_user}","gists_url":"https://api.github.com/users/ricardopereira/gists{/gist_id}","starred_url":"https://api.github.com/users/ricardopereira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricardopereira/subscriptions","organizations_url":"https://api.github.com/users/ricardopereira/orgs","repos_url":"https://api.github.com/users/ricardopereira/repos","events_url":"https://api.github.com/users/ricardopereira/events{/privacy}","received_events_url":"https://api.github.com/users/ricardopereira/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"cnoon","id":169110,"avatar_url":"https://avatars.githubusercontent.com/u/169110?v=3","gravatar_id":"","url":"https://api.github.com/users/cnoon","html_url":"https://github.com/cnoon","followers_url":"https://api.github.com/users/cnoon/followers","following_url":"https://api.github.com/users/cnoon/following{/other_user}","gists_url":"https://api.github.com/users/cnoon/gists{/gist_id}","starred_url":"https://api.github.com/users/cnoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnoon/subscriptions","organizations_url":"https://api.github.com/users/cnoon/orgs","repos_url":"https://api.github.com/users/cnoon/repos","events_url":"https://api.github.com/users/cnoon/events{/privacy}","received_events_url":"https://api.github.com/users/cnoon/received_events","type":"User","site_admin":false},"assignees":[{"login":"cnoon","id":169110,"avatar_url":"https://avatars.githubusercontent.com/u/169110?v=3","gravatar_id":"","url":"https://api.github.com/users/cnoon","html_url":"https://github.com/cnoon","followers_url":"https://api.github.com/users/cnoon/followers","following_url":"https://api.github.com/users/cnoon/following{/other_user}","gists_url":"https://api.github.com/users/cnoon/gists{/gist_id}","starred_url":"https://api.github.com/users/cnoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnoon/subscriptions","organizations_url":"https://api.github.com/users/cnoon/orgs","repos_url":"https://api.github.com/users/cnoon/repos","events_url":"https://api.github.com/users/cnoon/events{/privacy}","received_events_url":"https://api.github.com/users/cnoon/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2016-10-30T22:44:24Z","updated_at":"2016-11-13T02:01:12Z","closed_at":"2016-11-13T02:01:12Z","body":"**Pod version:** 3.5.1\n**Swift version:** 2.2\n\n<img width=\"571\" alt=\"screen_shot_2016-06-29_at_00_01_59\" src=\"https://cloud.githubusercontent.com/assets/3541185/19840559/3cefe120-9ef0-11e6-99f5-c3a2e69a5d20.png\">\n\nI found the [source of the problem](https://github.com/Alamofire/Alamofire/blob/769818dc764dc2dd465ff64ba413af6acc729b2f/Source/Upload.swift#L324). The temporary file should be removed after the operation ends. According to the [documentation](https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW4), the temporary folder only gets cleaned when the app is not running so, basically, it means that if the user never decides to kill the app or never reboots his device then, the temporary folder will remain.\n\nAny clue on where to put the code to clean up the temporary file?\n"},"comment":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/comments/260161502","html_url":"https://github.com/Alamofire/Alamofire/issues/1742#issuecomment-260161502","issue_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/1742","id":260161502,"user":{"login":"cnoon","id":169110,"avatar_url":"https://avatars.githubusercontent.com/u/169110?v=3","gravatar_id":"","url":"https://api.github.com/users/cnoon","html_url":"https://github.com/cnoon","followers_url":"https://api.github.com/users/cnoon/followers","following_url":"https://api.github.com/users/cnoon/following{/other_user}","gists_url":"https://api.github.com/users/cnoon/gists{/gist_id}","starred_url":"https://api.github.com/users/cnoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnoon/subscriptions","organizations_url":"https://api.github.com/users/cnoon/orgs","repos_url":"https://api.github.com/users/cnoon/repos","events_url":"https://api.github.com/users/cnoon/events{/privacy}","received_events_url":"https://api.github.com/users/cnoon/received_events","type":"User","site_admin":false},"created_at":"2016-11-13T02:01:12Z","updated_at":"2016-11-13T02:01:12Z","body":"Hi @ricardopereira,\r\n\r\nThanks for opening up this issue. I've just pushed up 9688b16f into `master` which automatically removes the temp file from disk after the upload completes. This will be part of the Alamofire 4.1.0 release which should be out by Monday.\r\n\r\nIf you're not using the latest version of Alamofire, you could manually delete the file like so in a `response` handler.\r\n\r\n```swift\r\nAlamofire.upload(\r\n    multipartFormData: { multipartFormData in\r\n        multipartFormData.append(unicornImageURL, withName: \"unicorn\")\r\n        multipartFormData.append(rainbowImageURL, withName: \"rainbow\")\r\n    },\r\n    to: \"https://httpbin.org/post\",\r\n    encodingCompletion: { encodingResult in\r\n        switch encodingResult {\r\n        case .success(let upload, _, streamFileURL):\r\n            upload.responseJSON { response in\r\n                debugPrint(response)\r\n                \r\n                // This is how you can remove the file\r\n                if let streamFileURL = streamFileURL {\r\n                    do {\r\n                        try FileManager.default.removeItem(at: streamFileURL)\r\n                    } catch {\r\n                        print(\"Failed to remove stream file at URL: \\(streamFileURL) - error: \\(error)\")\r\n                    }\r\n                }\r\n            }\r\n        case .failure(let encodingError):\r\n            print(encodingError)\r\n        }\r\n    }\r\n)\r\n```\r\n\r\nCheers. 🍻"}}
{"actor":{"display_login":"cnoon"}}