Beispiel #1
0
def resume_session(data):
    req = requests.get(data["uploadUrl"])
    HttpResponse(req.status_code, req.headers, req.content)
    result = convert_utf8_dict_to_dict(req.json())
    for k in ("expirationDateTime", "nextExpectedRanges"):
        data[k] = result[k]
    return data
Beispiel #2
0
def get_item_temp_download_info(item):
    """onedrivesdk.model.item.Item->(str, int, str)
    
    Get the direct download link of a file item so
    we can use tools like aria2 or make our own download.
    
    This link is only vaild for a few minutes.
    
    Return:
    
    (URL, file_size)
    
    We cannot return a hash since only personal has SHA1,
    sometimes only quickXorHash. 
    
    """
    file_info = convert_utf8_dict_to_dict(item.to_dict())
    return (file_info['@content.downloadUrl'],
            file_info['size'], )
Beispiel #3
0
def get_item_temp_download_info(item):
    """onedrivesdk.model.item.Item->(str, int, str)

    Get the direct download link of a file item so
    we can use tools like aria2 or make our own download.

    This link is only vaild for a few minutes.

    Return:

    (URL, file_size)

    We cannot return a hash since only personal has SHA1,
    sometimes only quickXorHash.

    """
    file_info = convert_utf8_dict_to_dict(item.to_dict())
    return (file_info['@content.downloadUrl'],
            file_info['size'],)
Beispiel #4
0
def create_session(api_base_url, token, source_file, dest_path):
    filename = os.path.basename(source_file)
    if not dest_path.endswith('/'):
        dest_path += '/'
    dest_path += filename

    api_url = api_base_url + \
        'drive/root:{dest_path}:/upload.createSession'.format(
            dest_path=dest_path)
    headers = {
        'Authorization': 'bearer {access_token}'.format(access_token=token),
        'content-type': 'application/json'
    }
    info_json = json.dumps(
        {'item': {
            '@name.conflictBehavior': 'fail',
            'name': filename
        }},
        sort_keys=True)

    # logger.debug("headers: %s, request data: %s" % (headers, info_json))
    req = requests.post(api_url, data=info_json, headers=headers)
    HttpResponse(req.status_code, req.headers, req.content)
    return convert_utf8_dict_to_dict(req.json())