A partial archive of https://discourse-mediawiki.wmflabs.org as of Saturday May 21, 2022.

Chunked Uploading using API:Upload

Mansi29ag

Hello, I am writing code for testing API:Upload for chunked uploading.
Code: link
Error: 'File upload parameter “chunk” is not a file upload; be sure to use “multipart/form-data” for your POST and include a filename in the “Content-Disposition” header.

The error says chunk is not a file upload but when I pass the exact same content in ‘file’ parameter then the code runs successfully. Here file parameter also has to be file upload. Since both are file uploads, I am unable to understand why it is giving error.

Code for passing in file parameter

jeropbrenda

From the documentation,

When uploading files directly, the request must use multipart/form-data as Content-Type

So you need to pass ‘chunk’ to ‘files’ and not to ‘data’ so that the correct Content-Type is set. i.e

PARAMS_4 = {
        "action": "upload",
        "filename": 'a.jpg',
        'stash' : 1,
        "filesize": file_size,
        "filekey" : DATA["upload"]["filekey"],
        "offset" : 0,
        "format" : "json",
        "token" : CSRF_TOKEN,
        }
files={'file': ('a.jpg', open('f.jpg','rb')), 'chunk': ('temp.jpg', chunk) }  
R = S.post(URL, files=files, data=PARAMS_4)
Mansi29ag

Thanks @jeropbrenda for the help. My concepts were not cleared.