fine-uploader icon indicating copy to clipboard operation
fine-uploader copied to clipboard

customHeaders may be a function for signature and uploadSuccess, but not deleteFile

Open nalbion opened this issue 8 years ago • 3 comments

Type of issue

bug

Uploader type

S3

Bug details

Fine Uploader version

5.11.9

Browsers where the bug is reproducible

all

Operating systems where the bug is reproducible

all

Exact steps required to reproduce the issue

  • Configure the uploader as per the next section
  • create a function which periodically updates $rootScope.authHeader with a new auth token.
  • upload a file (this works for me)
  • attempt to delete the file and observe the lack of Authorization header in the request.

All of your Fine Uploader initialization JavaScript code [REQUIRED]

var customHeaders = () => {
              return {
                  Authorization: $rootScope.authHeader
              }
          };

var uploader = new qq.s3.FineUploader({
           ...
           signature: {
                endpoint: domain + '/file-uploads/sign-request',
                version: 4,
                customHeaders: customHeaders
            },
            uploadSuccess: {
                endpoint: domain + '/file-uploads/upload-complete',
                customHeaders: customHeaders
            },
            deleteFile: {
                enabled: true,
                endpoint: domain + '/file-uploads',
                customHeaders: customHeaders
            },
});

Detailed explanation of the problem

Sure, the examples show that customHeaders can be configured as an object, but the code (most of it) allows the application to provide a function, so the headers can be generated for each request.

At line 4719 of s3.fine-uploader.js (seems to originate here) the standard pattern:

requester = qq.extend(this, new qq.AjaxRequester({
    ...
    customHeaders: options.customHeaders,

is swapped for:

requester = qq.extend(this, new qq.AjaxRequester({
    ...
    customHeaders: function(id) {
        return options.customHeaders.get(id);
    },

I understand that this "feature" that I was using for the other requests is used internally:

function setHeaders(id) {
    ...
    qq.extend(allHeaders, qq.isFunction(customHeaders) ? customHeaders(id) : customHeaders);

...but it's frustrating that now I need to come up with a new approach to push changes to the FineUploader config whenever the auth header needs to change.

nalbion avatar Jan 25 '17 06:01 nalbion

Thanks for the report. If you'd like to see this in a near-future version of Fine Uploader, a pull request will speed things up. I don't anticipate that I personally will have time to address this anytime soon.

rnicholus avatar Jan 25 '17 06:01 rnicholus

@rnicholus thanks for the quick response. Can you explain the rationale behind providing an id param to the customHeaders (internal) function for deleteFile() (and not for the sign/uploadComplete)?

I think I'll just settle for "Plan B":

    $rootScope.$watch('authHeader', (value) => {
          console.info('...now we need to update uploader config with', value, uploader);
          uploader.setDeleteFileCustomHeaders({Authorization: value});  // actually, I'd probably call the same `customHeaders()` function that I provide to the other endpoints`
      });

nalbion avatar Jan 25 '17 06:01 nalbion

no idea. that's been in place for at least 4 years most likely. inconsistent code evolution?

rnicholus avatar Jan 25 '17 06:01 rnicholus