massimo-cassandro / js-file-uploader

HTML5 Async File Uploader
https://massimo-cassandro.github.io/js-file-uploader/demo
MIT License
2 stars 3 forks source link

Pass in extra params #37

Open youradds opened 1 month ago

youradds commented 1 month ago

Hi,

I know this is probably a stale project - but I'll ask anyway. Why is there no way to pass in extra params with the POST? I want to pass an ID along with the request, so I can process it and know which listing its going with. But it seems that all it sends is:

          let fileData = new FormData();
          fileData.append('file', current_item.file);

I tested with:

          let fileData = new FormData();
          fileData.append('foo', "bar");
          fileData.append('file', current_item.file);

And that gets passed along fine - so shouldn't be much of a stretch to add this in?

massimo-cassandro commented 1 month ago

Hi @youradds js-file-uploader is a living project, I'm using it in more project, but I haven't updated it for a long time (although I would like to rewrite it almost completely). I'm pretty sure it's possible to do what you ask, but I'd have to do some checking. I'll let you know as soon as possible

massimo-cassandro commented 1 month ago

Can this answer to your request? https://massimo-cassandro.github.io/js-file-uploader/demo/extra-fields.html

You can add every type of estra fields with custom markup to each item, for example

<input type="hidden" name="foo" value="bar" />

I think this could solve your problem, let me know

Bye

youradds commented 1 month ago

Thanks. I'm not sure that does though? The FormData() only seems to have the "file" in it:

          let fileData = new FormData();
          fileData.append('file', current_item.file);
          ajax.send( fileData );

What I've done, is modified the core code so I can pass in an extra param:

          let fileData = new FormData();
          fileData.append('link_id_fk', window.VARS.linkID);
          fileData.append('file', current_item.file);
          ajax.send( fileData );

Cheers

Andy

youradds commented 1 month ago

I think my solution will work for me now (I've copied the modified file so it doesn't break with future updates). The final bit I need to do, is work out how to pre-fill with existing images. My system will need images uploaded - but also when we modify the listing, it needs to have the current images pre-filled as well. I had a look at the demo, but can't see any examples on how to do that? (or in the docs)

https://massimo-cassandro.github.io/js-file-uploader/demo/

Is this possible?

UPDATE - never mind, I worked it out based on that demo you gave:

                options: {
                    uploader_url: '/cgi-bin/admin/upload.cgi',
                    multiple: true,
                    filetype: "img",
                    sortable: true,
                    values: [
                    {
                        "id": "123",
                        "rel_id" : "1123",
                        "name": "gigi-1508584-unsplash.jpg",
                        "src": "test-files/gigi-1508584-unsplash.jpg",
                        "wi": 1199,
                        "he": 1600,
                        "size": 175418,
                        "publish": 1,
                        "caption": "Simatai Great Wall, Beijing, China (@ling_gigi/Unsplash)"
                      },
                    ]
                },

Cheers

Andy