def aip_file_download(request, uuid): # get file basename file = models.File.objects.get(uuid=uuid) file_basename = os.path.basename(file.currentlocation) # get file's AIP's properties sipuuid = helpers.get_file_sip_uuid(uuid) aip = elasticSearchFunctions.connect_and_get_aip_data(sipuuid) aip_filepath = aip.filePath # create temp dir to extract to temp_dir = tempfile.mkdtemp() # work out path components aip_archive_filename = os.path.basename(aip_filepath) subdir = os.path.splitext(aip_archive_filename)[0] path_to_file_within_aip_data_dir \ = os.path.dirname(file.originallocation.replace('%transferDirectory%', '')) file_relative_path = os.path.join(subdir, 'data', path_to_file_within_aip_data_dir, file_basename) #return HttpResponse('7za e -o' + temp_dir + ' ' + aip_filepath + ' ' + file_relative_path) # extract file from AIP command_data = [ '7za', 'e', '-o' + temp_dir, aip_filepath, file_relative_path ] subprocess.call(command_data) # send extracted file extracted_file_path = os.path.join(temp_dir, file_basename) return helpers.send_file(request, extracted_file_path)
def aip_file_download(request, uuid): # get file basename file = models.File.objects.get(uuid=uuid) file_basename = os.path.basename(file.currentlocation) # get file's AIP's properties sipuuid = helpers.get_file_sip_uuid(uuid) es_client = elasticSearchFunctions.get_client() aip = elasticSearchFunctions.get_aip_data(es_client, sipuuid, fields='uuid,name,filePath,size,origin,created') aip_filepath = aip['fields']['filePath'][0] # work out path components aip_archive_filename = os.path.basename(aip_filepath) # splittext doesn't deal with double extensions, so special-case .tar.bz2 if aip_archive_filename.endswith('.tar.bz2'): subdir = aip_archive_filename[:-8] else: subdir = os.path.splitext(aip_archive_filename)[0] # Strip %Directory% from the path path_to_file_within_aip_data_dir = os.path.dirname(file.currentlocation.replace('%transferDirectory%', '').replace('%SIPDirectory%', '')) file_relative_path = os.path.join( subdir, 'data', path_to_file_within_aip_data_dir, file_basename ) redirect_url = storage_service.extract_file_url(aip['fields']['uuid'][0], file_relative_path) return helpers.stream_file_from_storage_service(redirect_url, 'Storage service returned {}; check logs?')
def send_thumbnail(request, fileuuid): # get AIP location to use to find root of AIP storage sipuuid = helpers.get_file_sip_uuid(fileuuid) aip = elasticSearchFunctions.connect_and_get_aip_data(sipuuid) aip_filepath = aip.filePath # strip path to AIP from root of AIP storage for index in range(1, 10): aip_filepath = os.path.dirname(aip_filepath) # derive thumbnail path thumbnail_path = os.path.join( aip_filepath, 'thumbnails', sipuuid, fileuuid + '.jpg' ) # send "blank" thumbnail if one exists: # Because thumbnails aren't kept in ElasticSearch they can be queried for, # during searches, from multiple dashboard servers. # Because ElasticSearch don't know if a thumbnail exists or not, this is # a way of not causing visual disruption if a thumbnail doesn't exist. if not os.path.exists(thumbnail_path): thumbnail_path = os.path.join(settings.BASE_PATH, 'media/images/1x1-pixel.png') return helpers.send_file(request, thumbnail_path)
def send_thumbnail(request, fileuuid): # get AIP location to use to find root of AIP storage sipuuid = helpers.get_file_sip_uuid(fileuuid) thumbnail_path = os.path.join(settings.SHARED_DIRECTORY, 'www', 'thumbnails', sipuuid, fileuuid + '.jpg') # send "blank" thumbnail if one exists: # Because thumbnails aren't kept in ElasticSearch they can be queried for, # during searches, from multiple dashboard servers. # Because ElasticSearch don't know if a thumbnail exists or not, this is # a way of not causing visual disruption if a thumbnail doesn't exist. if not os.path.exists(thumbnail_path): thumbnail_path = os.path.join(settings.BASE_PATH, 'media/images/1x1-pixel.png') return helpers.send_file(request, thumbnail_path)
def aip_file_download(request, uuid): # get file basename file = models.File.objects.get(uuid=uuid) file_basename = os.path.basename(file.currentlocation) # get file's AIP's properties sipuuid = helpers.get_file_sip_uuid(uuid) aip = elasticSearchFunctions.connect_and_get_aip_data(sipuuid) aip_filepath = aip.filePath # create temp dir to extract to temp_dir = tempfile.mkdtemp() # work out path components aip_archive_filename = os.path.basename(aip_filepath) subdir = os.path.splitext(aip_archive_filename)[0] path_to_file_within_aip_data_dir \ = os.path.dirname(file.originallocation.replace('%transferDirectory%', '')) file_relative_path = os.path.join( subdir, 'data', path_to_file_within_aip_data_dir, file_basename ) #return HttpResponse('7za e -o' + temp_dir + ' ' + aip_filepath + ' ' + file_relative_path) # extract file from AIP command_data = [ '7za', 'e', '-o' + temp_dir, aip_filepath, file_relative_path ] subprocess.call(command_data) # send extracted file extracted_file_path = os.path.join(temp_dir, file_basename) return helpers.send_file(request, extracted_file_path)
def send_thumbnail(request, fileuuid): # get AIP location to use to find root of AIP storage sipuuid = helpers.get_file_sip_uuid(fileuuid) aip = elasticSearchFunctions.connect_and_get_aip_data(sipuuid) aip_filepath = aip.filePath # strip path to AIP from root of AIP storage for index in range(1, 10): aip_filepath = os.path.dirname(aip_filepath) # derive thumbnail path thumbnail_path = os.path.join(aip_filepath, 'thumbnails', sipuuid, fileuuid + '.jpg') # send "blank" thumbnail if one exists: # Because thumbnails aren't kept in ElasticSearch they can be queried for, # during searches, from multiple dashboard servers. # Because ElasticSearch don't know if a thumbnail exists or not, this is # a way of not causing visual disruption if a thumbnail doesn't exist. if not os.path.exists(thumbnail_path): thumbnail_path = os.path.join(settings.BASE_PATH, 'media/images/1x1-pixel.png') return helpers.send_file(request, thumbnail_path)