def tarload(request, *args, **kwargs): """ Download group of files in TAR format @param path : Relative path of target files @param files[] : List of files """ path = request.POST.get('path') files = request.POST.getlist('files[]') # 권한 확인 fileManager = CELLAR_FileManager(request) if path is None or not fileManager.isReadable(path) : raise PermissionDenied dirs = path.split("/"); while "" in dirs : dirs.remove("") dirs.reverse() tarStream = TarStream.open(fileManager.getFullPath(path), 128) for file in files : tarStream.add(file) response = StreamingHttpResponse(tarStream, content_type='application/x-tar') response['Content-Length'] = tarStream.getTarSize() response['Content-Disposition'] = 'attachment' return response
def getUserAuthority(request, *args, **kwargs): path = request.POST.get("path") fileManager = CELLAR_FileManager(request) response = { "code" : 0, "message" : "", "path" : path, "register" : False, "readable" : fileManager.isReadable(path), "writeable" : fileManager.isWriteable(path), "deletable" : fileManager.isDeletable(path) } return HttpResponse(json.dumps(response))
def download(request, *args, **kwargs): """ Download a file @param kwargs: filepath : Relative file path of target file. Root is user home. """ target = kwargs['filepath'] # Authority Check fileManager = CELLAR_FileManager(request) if target is None or not fileManager.isReadable(os.path.dirname(target)) : raise PermissionDenied fullPath = UserInfo.getUserInfo(request).getHomePath() + "/" + target response = StreamingHttpResponse(FileWrapper(open(fullPath, mode='rb')), content_type='application/octet-stream') response['Content-Length'] = os.path.getsize(fullPath) response['Content-Disposition'] = 'attachment' return response