Problem/Motivation

In #3221796: [META] Modernise file upload logic we identified the need for stream file uploads to get the client original filename from the content-disposition header for REST and JSON API file uploads.

Lets create a service to do this.

Steps to reproduce

Proposed resolution

Create a content disposition filename parser.

Remaining tasks

  • Create the content disposition filename parser
  • Replace usage in REST module
  • Replace usage in JSON API module

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3380379

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Issue summary: View changes
Status: Active » Needs review
  • Creates the content disposition filename parser
  • Replaces usage in REST module
  • Replaces usage in JSON API module
kim.pepper’s picture

Title: Create content disposition filename extractor » Create content disposition filename extractor and deprecate duplicate code in REST and JSON API
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Seems like a good change.
CR reads well also and includes removed functions.

quietone’s picture

I'm triaging RTBC issues. I re-read the IS and the comments. I didn't find any unanswered questions.

I skimmed the MR. At first I thought that the constant REQUEST_HEADER_FILENAME_REGEX would need to be renamed because of the coding standards for Constants. That states that "Module-defined constant names should also be prefixed by an uppercase spelling of the module that defines them." But the I searched core and found it used in two other files, one in the files module and one in jsonapi. It would be better to keep the name the same for now and fix it later.

I think the CR could use a more succinct title and before/after code samples.

kim.pepper’s picture

"Module-defined constant names should also be prefixed by an uppercase spelling of the module that defines them."

That makes sense if it's in a *.module file, but this will always be called with \Drupal\file\Upload\ContentDispositionFilenameParser::REQUEST_HEADER_FILENAME_REGEX which clearly shows the module and the class it comes from.

In regards to the CR, I wasn't sure if this issue actually justified one. I don't think there is a before and after needed as no one is calling this code. Its an internal protected method that is duplicated in two places: TemporaryJsonapiFileFieldUploader and FileUploadResource. This issue removes the duplication into shared code.

quietone’s picture

@kim.pepper, thanks for the explanations. I do see that I must read more carefully!

kim.pepper’s picture

Priority: Normal » Critical

Blocking a critical #2940383: [META] Unify file upload logic of REST and JSON:API therefore this is also critical.

kim.pepper’s picture

Status: Reviewed & tested by the community » Needs review

I changed this to a static method, as we are only using the FileSystem dependency for the basename method. And since we are just parsing a filename in content disposition header, we don't need to support StreamWrappers. Therefore the standard PHP basename function should be fine.

One less service to inject!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems change to static method is fine. Not sure if it should be noted in the CR or if that matters.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
kim.pepper’s picture

Status: Needs work » Reviewed & tested by the community

Re-rolled

  • larowlan committed 56b614e7 on 11.x
    Issue #3380379 by kim.pepper, smustgrave, quietone: Create content...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 11.x
Published change record

larowlan’s picture

Updated the change record to reflect this uses a static now and not a service

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.