PUT request fails when both utf8 and binary form-data is sent #1555
-
Describe the bug
I am trying to update the title and thumbnail of a video on PeerTube using form-data. The requests works fine as long as I don't send I am using get-stream so the request can be retried when client is not authenticated. My (naive) gut feeling is that Perhaps I am missing something? Actual behaviorPUT request fails Expected behaviorPUT request succeeds Code to reproduceimport got from "got"
import formData from "form-data"
import getStream from "get-stream"
import { readFile } from "fs"
import { promisify } from "util"
import { parse } from "path"
const readFileAsync = promisify(readFile)
const thumbnail =
"/Users/sunknudsen/Code/sunknudsen/sunknudsen-website/tube-manager/uJBgb8XJoA8.jpg"
!(async function () {
const form = new formData()
form.append("name", "foo")
form.append(
"thumbnailfile",
await readFileAsync(thumbnail, { encoding: "binary" }),
{
contentType: "image/jpeg",
filename: parse(thumbnail).base,
}
)
await got.put(
`https://peertube.sunknudsen.com/api/v1/videos/db71b05a-f648-4bdf-a037-6f91827ed0f3`,
{
headers: form.getHeaders(),
body: await getStream(form),
}
)
})() Checklist
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Well, this path doesn't exist on my computer... Can you please post something actually reproducible? |
Beta Was this translation helpful? Give feedback.
-
Hey @szmarczak, thanks for the follow-up. Unfortunately, putting together a reproducible example would require a lot of work given the PeerTube API requires authentication (I would have to build a mock API etc...). I ended up dropping My gut feeling is that That being said, it's likely I was messing something up at my end. Closing the issue. Thanks for |
Beta Was this translation helpful? Give feedback.
-
I'm pretty sure you forgot to use |
Beta Was this translation helpful? Give feedback.
I'm pretty sure you forgot to use
getStream.buffer
instead...