Skip to content

Added capabilities to have async header functions#823

Open
jzucchetto wants to merge 1 commit intopqina:masterfrom
jzucchetto:master
Open

Added capabilities to have async header functions#823
jzucchetto wants to merge 1 commit intopqina:masterfrom
jzucchetto:master

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.

2 participants