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)
def download_fs(request): shared_dir = os.path.realpath(helpers.get_server_config_value('sharedDirectory')) filepath = base64.b64decode(request.GET.get('filepath', '')) requested_filepath = os.path.realpath('/' + filepath) # respond with 404 if a non-Archivematica file is requested try: if requested_filepath.index(shared_dir) == 0: return helpers.send_file(request, requested_filepath) else: raise django.http.Http404 except ValueError: raise django.http.Http404
def transfer_file_download(request, uuid): # get file basename try: file = models.File.objects.get(uuid=uuid) except: raise Http404 file_basename = os.path.basename(file.currentlocation) shared_directory_path = helpers.get_server_config_value('sharedDirectory') transfer = models.Transfer.objects.get(uuid=file.transfer.uuid) path_to_transfer = transfer.currentlocation.replace('%sharedPath%', shared_directory_path) path_to_file = file.currentlocation.replace('%transferDirectory%', path_to_transfer) return helpers.send_file(request, path_to_file)
def download_fs(request): shared_dir = os.path.realpath(django_settings.SHARED_DIRECTORY) filepath = base64.b64decode(request.GET.get("filepath", "")) requested_filepath = os.path.realpath("/" + filepath) # respond with 404 if a non-Archivematica file is requested try: if requested_filepath.index(shared_dir) == 0: return helpers.send_file(request, requested_filepath) else: raise django.http.Http404 except ValueError: raise django.http.Http404
def transfer_file_download(request, uuid): # get file basename try: file = models.File.objects.get(uuid=uuid) except: raise Http404 shared_directory_path = django_settings.SHARED_DIRECTORY transfer = models.Transfer.objects.get(uuid=file.transfer.uuid) path_to_transfer = transfer.currentlocation.replace( '%sharedPath%', shared_directory_path) path_to_file = file.currentlocation.replace('%transferDirectory%', path_to_transfer) return helpers.send_file(request, path_to_file)
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 send_thumbnail(request, fileuuid): # get AIP location to use to find root of AIP storage es_client = es.get_client() aipfile = es.get_aipfile_data(es_client, fileuuid, fields="AIPUUID") sipuuid = aipfile["_source"]["AIPUUID"] 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)
def download(request, name): config_path = os.path.join(helpers.processing_config_path(), "{}ProcessingMCP.xml".format(name)) if not os.path.isfile(config_path): raise Http404 return helpers.send_file(request, config_path, force_download=True)
def download(request): return helpers.send_file(request, '/' + request.GET.get('filepath', ''))