【问题标题】:SharePoint Rest-API error with files >200 MB文件 > 200 MB 的 SharePoint Rest-API 错误
【发布时间】:2022-08-18 18:39:51
【问题描述】:

我在 SharePoint Online 上使用 Microsoft SharePoint REST API 并尝试上传 pandas DataFrame as csv。如果我将DataFrame 写入本地 csv 文件并开始上传,这可以正常工作(也适用于大文件)。

现在我尝试直接从内存上传DataFrame,但对于大于 200 MB 的文件会出现错误:

output = io.BytesIO()
writer = csv.writer(output)
df.to_csv(output, **kwargs)


guid = str(uuid.uuid4()) # unique ID for identifying current upload
file_full_path = r\"/sites/\" + self._site_name + \"/\" + lib_name + \"/\" + folder_path + \"/\" + file_name
offset = 0
file_size = output.__sizeof__()
next_buffer = True


url = self._URL + \"/_api/web/GetFolderByServerRelativeUrl(\'\" + lib_name + \"/\" + folder_path + \"\')/Files/add(url = \'\" + file_name + \"\')\"
response = requests.request(\"POST\", url, headers=headers, proxies=self._proxies)           
        
#init uploading
url = self._URL + \"/_api/web/GetFileByServerRelativePath(DecodedUrl=\'\" + file_full_path + \"\')/StartUpload(uploadId=guid\'\" + guid + \"\')\"
response = requests.request(\"POST\", url, headers=headers, proxies=self._proxies) 

#read file and upload it in a bytestream according to the given chunk size 
while next_buffer:
    actual_offset = offset
    offset += chunksize    
    # continue uploading in chunks as long as the upcoming chunk is smaller than the actual file.
    # otherwise finish uploading by decreasing the chunk size to the number of bytes left.
    if offset >= file_size:
        chunksize = file_size - (offset - chunksize)
        next_buffer = False
        url = self._URL + \"/_api/web/GetFileByServerRelativePath(DecodedUrl=\'\" + file_full_path + \"\')/FinishUpload(uploadId=guid\'\" + guid + f\"\',fileOffset={actual_offset})\"
    else:
        url = self._URL + \"/_api/web/GetFileByServerRelativePath(DecodedUrl=\'\" + file_full_path + \"\')/ContinueUpload(uploadId=guid\'\" + guid + f\"\',fileOffset={actual_offset})\"
    # read current chunk and add it to the request 
    output.seek(actual_offset)
    buffer = output.read(chunksize)
    response = requests.request(\"POST\", url, headers=headers, data = buffer, proxies=self._proxies) 

这是错误消息:

error\":{\"code:\"-2130575135, Microsoft.SharePoint.Utilities.SPBITSSessionIncompleteException

我不明白为什么我会收到此错误。

标签: python pandas sharepoint


【解决方案1】:

几个月前我使用过 API,如果我没记错的话,上传请求必须是 PUT。 一般的方法是创建一个uploadSession,一旦你得到uploadSessioUrl,你就可以PUT你的文档块,直到你完成。

Microsoft Error Codes 一如既往的有用

【讨论】:

    猜你喜欢
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多