r-hannuschka / ngx-fileupload

angular x fileupload
MIT License
18 stars 7 forks source link

[Question] How to send Custom fields with the file? #707

Closed JatinChimote closed 2 years ago

JatinChimote commented 2 years ago

Is your feature request related to a problem? Please describe.

How to send custom key value pairs along with file data. The current implementation considers a field 'metadata' in the UploadOption. I want to upload to S3 using a presigned url and I cannot send some custom keys like "policy", "signature" as there's simply no way to send direct formData fields. or Perhaps I am missing something.

Describe the solution you'd like there should be an option to pass any key value pair to the API that takes care of the uploads, not sure what metadata is the only field.

Describe alternatives you've considered Tried passing data directly but it gets stripped off in the request.

Additional context So I can : image I want to : image

r-hannuschka commented 2 years ago

Let me take a look onto this one, you want to add additional form data if i see this correctly and yes it seems currently not possible.

Should be not that hard if i see this correctly :) Maybe today after work or tomorrow but this week. You can open a pull request on this if you want, just let me know.

https://github.com/r-hannuschka/ngx-fileupload/blob/996d23a84152a3aa7b5abb50151fb74bc1ae454d/src/projects/core/src/lib/upload/src/upload.request.ts#L216

and update the options interface.

r-hannuschka commented 2 years ago

It should be now be possible if you add additionaldata to formData configuration like here.

Version 5.1.1 (still angular 13)

https://github.com/r-hannuschka/ngx-fileupload/blob/fab4c912d900da3449ef2030d6221a2908576149/src/projects/example/libs/pages/drop-zone/src/ui/drop-zone.ts#L25

  private uploadOptions: NgxFileUploadOptions = {
    url: "http://localhost:3000/upload/gallery",
    formData: {
      enabled: true,
      name: "picture",
      additionalData: {
        'token': 'foobar',
        'key': 'second',
        'key2': 'third'
      }
    },
  };
JatinChimote commented 2 years ago

Awesome! Thank you so much for your quick changes and response!

r-hannuschka commented 2 years ago

Thx alot just let me know if this is not working for you, i tested this only with unit tests :( need to add playwright finally for better coverage so i do not need to watch server logs anymore.