0

I have django view that gets request and I try to send pdf result of copyleak scan. I get file as request.body and request.FILES is empty.

I have checked copyleaks docs to see if I could pass extra argument as we should pass enctype="multipart/form-data" in django form to get files in request.FILES, but I did not see anything related.

I can read request body and write it to file, no problem here, but would be great if I directly get pdf file in request FILES.

myobj = json.dumps(
    {
        "pdfReport": {
            "verb": "POST",
            "endpoint": "https://aa67-212-47-137-71.in.ngrok.io/en/tool/copyleaks/download/",
        },
        "completionWebhook": "https://aa67-212-47-137-71.in.ngrok.io/en/tool/copyleaks/complete/",
        "maxRetries": 3,
    }
)

response = requests.post(
    "https://api.copyleaks.com/v3/downloads/file4/export/export16",
    headers=headers,
    data=myobj,
)


I tried to change Content-Type manually and got error

django.http.multipartparser.MultiPartParserError: Invalid boundary in multipart: None
Bad request (Unable to parse request body): /en/tool/copyleaks/download/
Sahil
  • 11
  • 3
  • Did you try passing "Content-Type": application/pdf header in your export request? Check the documentation on how to add a header to the export webhook: pdfReport.headers https://api.copyleaks.com/documentation/v3/downloads/export – Montoya Oct 30 '22 at 13:35

0 Answers0