Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for multipart/form-data file upload examples #241

Open
billiegoose opened this issue Jan 18, 2022 · 3 comments
Open

Better support for multipart/form-data file upload examples #241

billiegoose opened this issue Jan 18, 2022 · 3 comments

Comments

@billiegoose
Copy link

billiegoose commented Jan 18, 2022

Currently in the JS / Fetch example, it shows multipart file uploads like so:

image

This doesn't work as it just sends the string "logo.png" instead of the file.

A better example might be:

// HTML file input, chosen by user
const fileInputs = document.querySelectorAll('input[type="file"]')

form.append("file", fileInputs[0].files[0]);
@billiegoose billiegoose changed the title Better support for File uploads Better support for multipart/form-data file upload examples Jan 18, 2022
@reuben
Copy link

reuben commented Apr 13, 2023

Python / Requests snippet is also affected, and doesn't even include any code to upload the file:

import requests

url = "http://localhost/api/upload"

payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nfoo\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n\r\n-----011000010111000001101001--\r\n\r\n"
headers = {
    "Content-Type": "multipart/form-data; boundary=---011000010111000001101001",
    "Authorization": "Bearer foo"
}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

@AdrianMachado
Copy link

+1 on this issue - I feel file upload is a super common usecase that deserves some love

@mapix
Copy link

mapix commented Oct 11, 2024

+1 for python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants