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

Upload empty file #10113

Closed
ksv510 opened this issue Mar 6, 2020 · 11 comments · Fixed by #10236
Closed

Upload empty file #10113

ksv510 opened this issue Mar 6, 2020 · 11 comments · Fixed by #10236
Milestone

Comments

@ksv510
Copy link

ksv510 commented Mar 6, 2020

We have found the following PR https://github.com/playframework/playframework/pull/8882/files#diff-20801290d88b7f6470285127f95c3f0dR559

For obvious reasons however, uploading an empty file doesn't make a lot of sense

Why do you think that there is no sense to upload an empty file?

For example, I have implemented TODO list based on files. And file name is something like category. In this case, I cannot create empty category.

I know that this example is far-fetched. But all file systems allow creating empty file, so I believe you should too.

Currently, we need to upload empty files and we will make some hack to do it (((

@mkurz
Copy link
Member

mkurz commented Mar 6, 2020

Interesting. Maybe we can make that configurable. For the multipartform body parser and globally via application.conf.
Do you use java or scala?

@ksv510
Copy link
Author

ksv510 commented Mar 6, 2020

we use Java. It would be great if we can configure it. Thank you for the fast reply.

@JoeSilentJoe
Copy link

JoeSilentJoe commented Mar 12, 2020

@mkurz The same problem. When can I wait for the ability to download empty files to return?

@mkurz
Copy link
Member

mkurz commented Mar 12, 2020

I am very busy right now with other things, however maybe I can have a look in the next couple of days.

@JoeSilentJoe
Copy link

Thanks! It would be great!

@JoeSilentJoe
Copy link

Hello @mkurz !

Is there any progress on this issue?

@mkurz
Copy link
Member

mkurz commented Mar 20, 2020

@JoeSilentJoe Not yet, sorry. Even if I would fix this today, a new Play release will take a while anyway I guess. I put it onto my TODO list, hopefully the next days.

@mkurz mkurz removed the triage label Apr 2, 2020
@mkurz mkurz added this to the Play 2.8.2 milestone Apr 2, 2020
@mkurz
Copy link
Member

mkurz commented Apr 26, 2020

@ksv510 When you say empty category/empty file, do you mean you upload a file without body but with a filename? Or is the filename also non-existent? Can you post how the request (headers) looks like?

@mkurz
Copy link
Member

mkurz commented Apr 27, 2020

@ksv510 @JoeSilentJoe Here is the fix: #10236
Starting with Play 2.9 you will be able to set

play.http.parser.allowEmptyFiles = true

in conf/application.conf to globally allow empty file uploads.

However, because of compatibility reasons that config can't be backported to 2.8.x and 2.7.x.

But what I did is in #10237 and #10238 I backported the needed coded so you will be able to write your own body parsers that allow empty file uploads.
I uploaded an example app:
All you need to do is define a custom body parser that extends from BodyParser.MultipartFormData:
https://github.com/mkurz/play-empty-upload-allowed/blob/master/app/bodyparsers/CustomMultipartFormData.java
You can then use this body parser on your actions:
https://github.com/mkurz/play-empty-upload-allowed/blob/master/app/controllers/HomeController.java#L15

This will work once Play 2.8.2 and 2.7.5 is released (again, for Play 2.9.0 this won't be necessary, the config will be enough then)

@mkurz
Copy link
Member

mkurz commented Apr 27, 2020

Probably we can't backport to Play 2.7 because of problems its Scala 2.11 support is causing, see #10238 (comment)

@mergify mergify bot closed this as completed in #10236 May 19, 2020
@JoeSilentJoe
Copy link

When you say empty category/empty file, do you mean you upload a file without body but with a filename? Or is the filename also non-existent?

Upload a file without body but with a filename

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

Successfully merging a pull request may close this issue.

3 participants