Open wnnce opened 3 months ago
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
@efectn can you help here
@efectn can you help here
I implemented the requirement using fasthttp's multipart.NewWriter() and RawRequest
func upload(fileName string, reader io.ReadCloser) {
uploadToken := makeUploadToken(fileName, 1*time.Hour)
request := client.AcquireRequest()
requestBody := &bytes.Buffer{}
multipartWriter := multipart.NewWriter(requestBody)
fileWriter, err := multipartWriter.CreateFormFile("file", fileName)
if err != nil {
log.Fatalln(err)
}
if _, err = io.Copy(fileWriter, reader); err != nil {
log.Fatalln(err)
}
if err = multipartWriter.WriteField("key", fileName); err != nil {
log.Fatalln(err)
}
if err = multipartWriter.WriteField("token", uploadToken); err != nil {
log.Fatalln(err)
}
if err = multipartWriter.Close(); err != nil {
log.Fatalln(err)
}
request.SetRawBody(requestBody.Bytes())
request.AddHeader("Content-Type", multipartWriter.FormDataContentType())
response, err := request.Post(REGION)
if err != nil {
log.Fatalln(err)
}
fmt.Println(string(response.Body()))
}
same request here
Question Description
I have an interface that needs to use FormData to upload files, but the AddFormDate() provided can only add strings, while AddFile() adds the file to the files field and not to the FormDate.
Code Snippet (optional)
Checklist: