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

Added capabilities to have async header functions #823

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jzucchetto
Copy link

A big part of uploading is to validate that the data doesn't get corrupted. One way to do it is to do a checksum and send it to the server as a part of the headers. Most checksum functions are asynchronous and this change would allow these types of functions to be added to the Filepond headers.

Example:

const server = {
    url: '/api/http-upload/chunk',
    patch: {
      headers: async (chunk) => {
        const { data, file, offset } = chunk;

        const md5 = async () => await hashwasm.md5(new Uint8Array(await data.arrayBuffer()));

        return {
          'Content-Type': 'application/offset+octet-stream',
          'Upload-Offset': offset,
          'Upload-Length': file.size,
          'Upload-Name': file.name,
          'x-checksum-md5': await md5()
        };
      }
    }
  };

@rikschennink
Copy link
Collaborator

Excellent idea.

Can you move these outside of the Promise, I guess we can set them before applying the headers.

        // set type of response
        if (options.responseType) {
            xhr.responseType = options.responseType;
        }

        // set credentials
        if (options.withCredentials) {
            xhr.withCredentials = true;
        }

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 this pull request may close these issues.

None yet

2 participants