Skip to content

Commit

Permalink
Use context manager while uploading files. (#61)
Browse files Browse the repository at this point in the history
* use `with open() as ...` to better control context during file uploads.

* remove unused imports.
  • Loading branch information
willgraf authored Jun 23, 2020
1 parent dd1877a commit 3b5cbcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
11 changes: 5 additions & 6 deletions kiosk_client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,11 @@ def upload_file(self):
headers = self.headers.copy()
headers['Content-Type'] = ['multipart/form-data']
name = 'UPLOAD {}'.format(self.filepath)
payload = {
'file': (self.filepath, open(self.filepath, 'rb'))
}
response = yield self._retry_post_request_wrapper(host, name,
files=payload,
headers=headers)
with open(self.filepath, 'rb') as f:
payload = {'file': (self.filepath, f)}
response = yield self._retry_post_request_wrapper(host, name,
files=payload,
headers=headers)
uploaded_path = response.get('uploadedName')
defer.returnValue(uploaded_path) # "return" the value

Expand Down
3 changes: 0 additions & 3 deletions kiosk_client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@
from __future__ import division
from __future__ import print_function

import io
import json
import logging
import os
import shutil
import timeit
import uuid
import zipfile

import requests
from google.cloud import storage as google_storage
Expand Down

0 comments on commit 3b5cbcc

Please sign in to comment.