Skip to content

Commit

Permalink
Merge pull request #14 from neutrons/encoding_defect
Browse files Browse the repository at this point in the history
Decode plot data from bytestring to utf-8 before storing in database
  • Loading branch information
backmari authored Jun 10, 2024
2 parents 1e9ddb0 + 8833606 commit 05627f9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion live_data_server/plots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_data_type_from_data(cls, data):
Inspect the data to guess what type it is.
@param data: block of text to store
"""
if data.startswith(b'<div'):
if data.startswith('<div'):
return DATA_TYPES['html']
return DATA_TYPES['json']

Expand Down
2 changes: 1 addition & 1 deletion live_data_server/plots/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _store(request, instrument, run_id=None, as_user=False):
@param as_user: if True, we will store as user data
"""
if request.user.is_authenticated and 'file' in request.FILES:
raw_data = request.FILES['file'].read()
raw_data = request.FILES['file'].read().decode('utf-8')
data_type_default = PlotData.get_data_type_from_data(raw_data)
data_type = request.POST.get('data_type', default=data_type_default)
if as_user:
Expand Down
1 change: 1 addition & 0 deletions tests/test_post_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_get_request(data_server):
url = f"{base_url}?key={_generate_key(instrument, run_number)}"
http_request = requests.get(url)
assert http_request.status_code == http_ok
assert http_request.text == files["file"]

# test GET request - no key
# TODO: this should return 401 unauthorized
Expand Down

0 comments on commit 05627f9

Please sign in to comment.