def bulk_upload_DB(files): for entry in files: remote_path = entry['path'] date_str = entry['last_modified'] size = entry['size'] last_modified = datetime.strptime(date_str, '%Y-%m-%d') name = fs.file_name(remote_path) remote_parent = fs.parent_path(remote_path) remote_dir = create_hierarchy(remote_parent) try: tmp_file = File.objects.get(name=name, path=remote_dir) except: new_file = File(name=name, path=remote_dir, size=size, last_modified=last_modified) new_file.save()
def handle_upload(request): if request.method == 'POST': remote_path = request.POST['path'] date_str = str(request.POST['last_modified']) last_modified = datetime.strptime(date_str, '%Y-%m-%d') f = request.FILES['file'] temp_path = fs.save_from_upload(remote_path, f) file_info = fs.file_info(temp_path) remote_parent = fs.parent_path(remote_path) remote_dir = create_hierarchy(remote_parent) new_file = File(name=file_info['name'], path=remote_dir, size=file_info['size'], last_modified=last_modified) new_file.save() storage_ebs.upload_file(temp_path, remote_path) response = render(request, 'response.xml', {'status': '1', 'message': 'File uploaded successfully.'}, content_type='text/xml') else: response = render(request, 'response.xml', {'status': '0', 'message': 'Use POST for file uploads.'}, content_type='text/xml') return response