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

Process: Custom-Headers not applied, when Filesize < Chunk-Size #193

Closed
BuchholzTim opened this issue Jan 17, 2021 · 5 comments
Closed

Process: Custom-Headers not applied, when Filesize < Chunk-Size #193

BuchholzTim opened this issue Jan 17, 2021 · 5 comments

Comments

@BuchholzTim
Copy link

Describe the bug:
Currently Filepond does not send the filename on the first Process-Request, if it's uploading a file, which has a filesize greater than chunk-size. I also need to apply two additonal headers to the requests (projectId, Authorization).

Those two headers are easily applied by setting the server-Property to the following computed-Value:

computed: {
    headers() {
      return {
        Authorization: this.$auth.getToken('local'),
        projectId: this.projectId,
      };
    },
    server() {
      return {
        url: 'http://localhost:3001/api/filepond/',
        process: {
          url: 'process',
          headers: this.headers,
        },
        patch: {
          url: 'patch?id=',
          headers: this.headers,
        },
      };
    },
}

This applied my two custom headers additonally to everything filepond does on its own.

I tried setting the filename in the Process-Request by passing a Function instead of an Object to the server.process.headers-Value, as described in this Issue.

The new code looks like this:

  computed: {
    server() {
      return {
        url: 'http://localhost:3001/api/filepond/',
        process: {
          url: 'process',
          headers: (file, metaData) => this.processHeaders(file, metaData),
        },
        patch: {
          url: 'patch?id=',
          headers: (file, metaData) => this.headers(file, metaData),
        },
      };
    },
  },
  methods: {
    processHeaders(file, metaData) {
      // Log some stuff on Process - Irrelevant for this issue
      return this.headers(file, metaData);
    },
    headers(file, metaData) {
      return {
        Authorization: this.$auth.getToken('local'),
        projectId: this.projectId,
        'Upload-Length': file.file ? file.file.size : file.size,
        'Upload-Name': file.name ? file.name : file.file.name,
        'Upload-Offset': file.file ? file.offset : undefined,
      };
    },
  }

This Code works perfectly fine for any filesize greater than chunk-size. The first Process-Request receives all the necessary headers and all Patch-Requests afterwards also receive them.

If the file however can be uploaded in one request (i.e. filesize < chunk-size ), then the Process-Request does not receive my headers and in consequence is not authorized to upload to the backend.

In fact, the processHeaders(file, metaData)-Function only gets called, when a Patch-Request will follow. On a single Process-Request, it won't even call the method.

Information about your project:

  • Firefox 84.0.2
  • Windows 10
  • FilePond 4.25.1
  • Vue-Filepond 6.0.3
@rikschennink
Copy link
Collaborator

Thanks for the detailed issue. I wonder if chunkForce would fix this?

@BuchholzTim
Copy link
Author

Thanks for the reply and the nice workaround.
Setting chunkForce fixes my particular problem. Perhaps I overlooked it in the documentation.

@rikschennink
Copy link
Collaborator

Glad to hear that :)

I'll close the issue for you.

@akislawek
Copy link

@rikschennink I came across the same issue as @BuchholzTim, and found this behaviour confusing, especially that the docs don't mention this in the "Server configuration" section (https://pqina.nl/filepond/docs/api/server/#process-chunks), leaving me think that once I set chunkUploads to true (as mentioned in the docs) all files would follow the same process.

Perhaps adding a comment regarding this (and the chunkForce option) in the "process chunks" section of the docs would save people time in the future (it would surely save me time not having to code a workaround for this :)

thanks for the great plugin, by the way!

@rikschennink
Copy link
Collaborator

Good point. I've added an additional entry to the server docs.

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

3 participants