Exemple #1
0
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))
Exemple #2
0
def upload(request, *args, **kwargs):
    response = { 
        "status"    : "success", 
        "message"   : "" 
    }
    
    fileManager = CELLAR_FileManager(request)
    filename    = request.POST.get("name")
    cwd         = request.POST.get("cwd")
    if cwd is None or not fileManager.isWriteable(cwd) :
        response["status"] = "error"
        response["message"] = "해당 경로에 쓰기 권한이 없습니다."
        return HttpResponseServerError(json.dumps(response))
     
    file = request.FILES["file"]
    if not file :
        response["status"] = "error"
        response["message"] = "파일이 정상적으로 업로드 되지 않았습니다."
        return HttpResponseServerError(json.dumps(response))
     
    dstPath = fileManager._root_norm + cwd + filename
    chunk   = int(request.POST.get("chunk"))
    chunks  = int(request.POST.get("chunks"))
     
    if chunk == 0 :
        info("Upload : " + dstPath + " start")
        mode = "wb"
    else :
        mode = "ab"
    
    info("Upload : " + dstPath + " ({0} / {1})".format(chunk + 1, chunks)) 
    with open(dstPath, mode) as destination:
        destination.write(file.file.read())
    file.file.close()
    
    if chunk + 1 == chunks :
        info("Upload : " + dstPath + " finished")
        
    return HttpResponse(json.dumps(response))