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

Allow to change the endpoint option to the uploadItem #26

Closed
wil92 opened this issue Mar 21, 2019 · 0 comments
Closed

Allow to change the endpoint option to the uploadItem #26

wil92 opened this issue Mar 21, 2019 · 0 comments

Comments

@wil92
Copy link

wil92 commented Mar 21, 2019

I'm using the library in a system where the files can be uploaded to more than one endpoint, and is a little bit difficult to change the endpoint for different files, because is not nice to change the service configuration each time i need to upload a file (that what i'm doing now):

  1. define autoUpload as false
options: UploadxOptions = {
    concurrency: 2,
    autoUpload: false,
    chunkSize: 1024 * 256 * 8
  };
  1. this.uploadxService.handleFile(file); // Put the file ready to upload
  2. subscribe and start upload the file
let itemId = null;
return this.uploadsProgress.pipe(
      map((item: UploadState) => {
        if (!itemId && item.status === 'added') {
          itemId = item.uploadId;
          this.uploadxService.control({
            action: 'upload',
            itemOptions: {
              token: 'toekneeeeeeeeeee',
              uploadId: itemId,
              endpoint: apiEndpoint,
              method: 'POST'
            } as UploadItem
          } as UploadxControlEvent);
        }
        return item;
      }),
      filter((item: UploadState) => item.status === 'cancelled' || item.status === 'complete' || item.status === 'error' && item.uploadId === itemId)
    );

this should work but the endpoint is not updated in the configure method in Uploader class:

configure(item = {} as UploadItem): void {
    const { metadata, headers, token } = item;
    this.metadata = {
      name: this.name,
      mimeType: this.mimeType,
      size: this.size,
      ...unfunc(metadata || this.metadata, this.file)
    };
    this.chunkSize = this.options.chunkSize || this.chunkSize;
    this.maxRetryAttempts = this.options.maxRetryAttempts || this.maxRetryAttempts;
    this.refreshToken(token);
    this.headers = { ...this.headers, ...unfunc(headers, this.file) };
  }

Other idea is to return the uploader in the handler method because right now i need to take the uploaderId in the uploadsProgress as an even of the service.

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