コード例 #1
0
def CreateUploadSession(disk_id, fileName, remotePath):
    if remotePath == "None":
        remotePath = "/"
    data_list = driveModels.drive_list.find_by_id(disk_id)
    token = json.loads(json.loads(data_list.token))
    url = config.app_url + '/v1.0/me/drive/root:{}/{}:/createUploadSession'.format(remotePath,fileName)
    headers = {'Authorization': 'bearer {}'.format(token["access_token"]), 'Content-Type': 'application/json'}
    data = {
        "item": {
            "@microsoft.graph.conflictBehavior": "fail",
        }
    }
    try:
        pull_res = requests.post(url, headers=headers, data=json.dumps(data))
        if pull_res.status_code == 409:
            return False
        else:
            pull_res = json.loads(pull_res.text)
            if 'error' in pull_res.keys():
                driveLogic.reacquireToken(disk_id)
                CreateUploadSession(disk_id, fileName, remotePath)
            else:
                    return pull_res
    except Exception as e:
        return False
コード例 #2
0
def putfilesmall(disk_id, dirve_id, fileName, remotePath, times=1):
    if int(times) > 3:
        return
    else:
        times += 1
    if remotePath == "None":
        remotePath = "/"
    data_list = driveModels.drive_list.find_by_id(disk_id)
    token = json.loads(json.loads(data_list.token))
    url = config.app_url + '/v1.0/me/drive/items/root:{}/{}:/content'.format(remotePath, fileName)
    headers = {'Authorization': 'bearer {}'.format(token["access_token"])}
    pull_res = requests.put(url, headers=headers, data=open(os.getcwd()+"/temp_uploads/" + str(dirve_id) + "/" + fileName, 'rb'))
    pull_res = json.loads(pull_res.text)
    if 'error' in pull_res.keys():
        driveLogic.reacquireToken(disk_id)
        putfilesmall(disk_id, dirve_id, fileName, remotePath, times)
    else:
        return pull_res
コード例 #3
0
def pull_dirve_file(chief_id, file_id):
    data_list = driveModels.drive_list.find_by_id(chief_id)
    token = json.loads(json.loads(data_list.token))
    BaseUrl = config.app_url + 'v1.0/me/drive/items/' + file_id
    headers = {'Authorization': 'Bearer {}'.format(token["access_token"])}
    try:
        get_res = requests.get(BaseUrl, headers=headers, timeout=30)
        get_res = json.loads(get_res.text)
        if 'error' in get_res.keys():
            logic.reacquireToken(chief_id)
            pull_dirve_file(chief_id, file_id)
        else:
            if '@microsoft.graph.downloadUrl' in get_res.keys():
                return {
                    "name": get_res["name"],
                    "url": get_res["@microsoft.graph.downloadUrl"]
                }
            else:
                pull_dirve_file(chief_id, file_id)
    except Exception as e:
        pass