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

missing filename and filetype in formdata (always setting default filename: blob) #25

Closed
yadav-saurabh opened this issue Oct 5, 2023 · 3 comments

Comments

@yadav-saurabh
Copy link
Contributor

yadav-saurabh commented Oct 5, 2023

Is there any way to send formdata?

If I send the form data like in the bellow code, I am getting file.name as blob for every single file

// server
 .post(
        '/pdf',
        async ({ body }) => {
            console.log(body)
            for (let index = 0; index < body.files.length; index++) {
                const file = body.files[index]
                console.log('file.name: ', file.name)
                console.log('file.size: ', file.size)
                console.log('file.type: ', file.type)
            }
            return { message: 'success got the file' }
        },
        {
            body: t.Object({ files: t.Files() })
        }
    )
// client
const client = edenTreaty<Server>('http://localhost:8080')


const files = e.target.files
const { data, error } = await client.pdf.post({ files: files })
// output using edenFetch or edenTreaty
{
  files: [
    Blob (0.27 MB)
  ]
}
file.name:  blob
file.size:  270947
file.type:  

using fetch or axios with formdata I am able to get the file.name correctly

// client
const formData = new FormData()
for (let i = 0; i < files.length; i++) {
    let file = files.item(i)
    formData.append('files', file)
}
await axios.post('http://localhost:8080/pdf', formData, {
    headers: { 'Content-Type': 'multipart/form-data' }
})
await fetch('http://localhost:8080/pdf', {
    method: 'POST',
    body: formData
})
// output using axois to fetch with formdata
{
  files: [
    Blob (0.27 MB)
  ]
}
file.name:  society.pdf
file.size:  270947
file.type:  
@yadav-saurabh
Copy link
Contributor Author

yadav-saurabh commented Oct 5, 2023

looked into the code, was able to fix it submitted a PR #26.

by using below code we can pass the formdata

// client
const client = edenTreaty<Server>('http://localhost:8080')


const files = e.target.files
const { data, error } = await client.pdf.post({ files: files })

@yadav-saurabh yadav-saurabh changed the title send formdata missing filename in formdata Oct 5, 2023
@yadav-saurabh yadav-saurabh changed the title missing filename in formdata missing filename in formdata (always setting default finename: blob) Oct 5, 2023
@yadav-saurabh yadav-saurabh changed the title missing filename in formdata (always setting default finename: blob) missing filename in formdata (always setting default filename: blob) Oct 5, 2023
@yadav-saurabh
Copy link
Contributor Author

it seems like file-type is also not missing as file-name is always set to blob

@yadav-saurabh yadav-saurabh changed the title missing filename in formdata (always setting default filename: blob) missing filename and filetype in formdata (always setting default filename: blob) Oct 12, 2023
@kyung-min-sun
Copy link

Yeah, I'm having similar problems as well with the filename omission. It'd be nice to have this fixed.

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

2 participants