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

FormData is broken as it expects the property "filename" to exist on an empty p.file #4

Open
rniedosmialek opened this issue Feb 27, 2024 · 3 comments
Assignees
Labels
awaiting user waiting for user to respond triage

Comments

@rniedosmialek
Copy link

Ran into an issue with FormData producing the following error.

ERRO[0309] TypeError: Cannot read property 'filename' of undefined

I found this condition is accessing "filename" with out evaluating p.file even exists

if (p.file.filename) { cd += '; filename="' + p.file.filename.replace(/"/g,'%22') + '"'; }

I had to update the condition to test for the existance of both.

// Check if p.file and p.file.filename exist before using if (p.file && p.file.filename) { cd += '; filename="' + p.file.filename.replace(/"/g,'%22') + '"'; }

@PeaceDate
Copy link

@olegbespalov Is any updates here?

@olegbespalov
Copy link
Contributor

Hey @rniedosmialek @PeaceDate

Sorry, it went off my radars 😢

It sounds like a bug on this corner case. Will it work for you if you manually form the file data, like:

fd.append('aTestFile', { data: null, filename: '', content_type: 'application/octet-stream' });

I'm curious to learn more about the case. So you want to test the multipart request where nothing passed, right?

In other words, what do you think the request should look like? Is it something like below?

POST /submit-form HTTP/1.1
Host: example.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: 342

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="text"

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename=""
Content-Type: application/octet-stream

------WebKitFormBoundary7MA4YWxkTrZu0gW--

@olegbespalov olegbespalov added the awaiting user waiting for user to respond label Apr 18, 2024
@PeaceDate
Copy link

@olegbespalov This is helps for now
fd.append('aTestFile', { data: null, filename: '', content_type: 'application/octet-stream' });

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

No branches or pull requests

3 participants