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

Free the getResponseBody #252

Closed
maertz opened this issue Jul 26, 2020 · 0 comments
Closed

Free the getResponseBody #252

maertz opened this issue Jul 26, 2020 · 0 comments

Comments

@maertz
Copy link
Contributor

maertz commented Jul 26, 2020

Is your feature request related to a problem? Please describe.
I'm not able to overwrite the getResponseBody method in my uploaderClass which extends the "Uploader" class.

Describe the solution you'd like
Make getResponseBody public to be able to take full control over the response body parsing on uploader class level.

Describe alternatives you've considered
Handle such behaviour on upload item level (not prefered) :)

Additional context
I've used the MultiPartFormData example within the "upload-examples" to demonstrate this.
image

export class MultiPartFormData extends Uploader {
  responseType = 'json' as XMLHttpRequestResponseType;

  private getResponseBody(xhr: any) { 
    let body: UploadAttachmentFilesResponse[] =
      'response' in xhr ? xhr.response : xhr.responseText;
    if (body && this.responseType === 'json' && typeof body === 'string') {
      try {
        body = JSON.parse(body);
      } catch (_a) {}
    }

    return body
  }

  async getFileUrl(): Promise<string> {
    this.offset = 0;
    const formData: FormData = new FormData();
    formData.append('files', this.file, this.file.name);
    await this.request({
      method: 'POST',
      body: formData,
      url: this.endpoint,
      progress: true
    });
    this.offset = this.size;
    const location = this.getValueFromResponse('location');
    return location ? resolveUrl(location, this.endpoint) : '';
  }

  async sendFileContent(): Promise<number | undefined> {
    return this.size;
  }

  async getOffset(): Promise<number | undefined> {
    return 0;
  }
}

Cheers :)

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

2 participants