Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/placer.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ def finalize(self):
'modified': cgi_field.modified,
'size': cgi_field.size,
'hash': cgi_field.hash,
'mimetype': cgi_field.mimetype,

'type': self.metadata['packfile']['type'],

Expand Down
24 changes: 23 additions & 1 deletion bin/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import time

from api import config
from api import util
from api.dao import containerutil
from api.dao.containerstorage import ProjectStorage
from api.jobs.jobs import Job
from api.jobs import gears
from api.types import Origin
from api.jobs import batch

CURRENT_DATABASE_VERSION = 35 # An int that is bumped when a new schema change is made
CURRENT_DATABASE_VERSION = 36 # An int that is bumped when a new schema change is made

def get_db_version():

Expand Down Expand Up @@ -1189,6 +1190,27 @@ def upgrade_to_35():
process_cursor(cursor, upgrade_to_35_closure)


def upgrade_to_36_closure(acquisition):

for f in acquisition['files']:
if not f.get('mimetype'):
logging.debug('file with name {} did not have mimetype'.format(f['name']))
f['mimetype'] = util.guess_mimetype(f['name'])

result = config.db.acquisitions.update_one({'_id': acquisition['_id']}, {'$set': {'files': acquisition['files']}})
if result.modified_count != 1:
raise Exception('Acquisition file not updated')

return True


def upgrade_to_36():
"""
scitran/core issue #931 - mimetype not set on packfile uploads
"""
cursor = config.db.acquisitions.find({'files': { '$gt': [] }, 'files.mimetype': None})
process_cursor(cursor, upgrade_to_36_closure)



###
Expand Down
6 changes: 6 additions & 0 deletions test/integration_tests/python/test_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,12 @@ def test_packfile_upload(data_builder, file_form, as_admin, as_root, api_db):
params={'token': token, 'metadata': metadata_json})
assert r.ok

# make sure file was uploaded and mimetype and type are properly set
packfile = as_admin.get('/acquisitions').json()[0]['files'][0]
assert packfile['mimetype'] == 'application/zip'
assert packfile['type'] == 'test'


# get another token (start packfile-upload)
r = as_admin.post('/projects/' + project + '/packfile-start')
assert r.ok
Expand Down