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

Multiple files in one POST request #272

Open
kjurl opened this issue Apr 17, 2022 · 8 comments
Open

Multiple files in one POST request #272

kjurl opened this issue Apr 17, 2022 · 8 comments

Comments

@kjurl
Copy link

kjurl commented Apr 17, 2022

The file picker option in the app doesn't support multiple files as of now, ( correct me if I'm wrong ) ... neither does it support Content-Type=multipart/form-data ... I know in a simple html form u can write something as `<input .... multiple="multiple" encoding="multipart/form-data" ... say I wanted to POST a request to that endpoint containing many files..

I'd like to see some kind of support for sending multiple ( say image files ) in a POST request preferably through the same file picker

Alternative: probably, using application/json and sending files after converting them into base64 then writing more server side logic to parse the json and covert them back to images, that's inconvenient, plus you can't use variables here, as there is no present functionality that helps to simplify this
( an alternative javascript solution can exist, but I'd still prefer to use the file picker ... also, the only language I know is python ... ^^")

I'm pretty new to all of this stuff, ...^^" .. so I have limited knowledge, feel free to ask more stuff or suggest me better solutions, thank you very much for your time

@Waboodoo
Copy link
Owner

Waboodoo commented Apr 18, 2022

Sending multiple files in one POST request is already supported.

When creating or editing a shortcut, go into the "Request Body / Parameters" section, and there change the "Request Body Type" to "Parameters (form-data)". Now use the plus button at the bottom right to add your parameters. Choose the "Multiple Files" option if you want to upload multiple files in a single parameter (analogous to what <input .... multiple="multiple"> would do). If you then execute this shortcut it will prompt you with a file picker, in which you can select multiple files, and those will be used for the parameter you set up.

Hope this helps. Let me know if something is unclear or does not work as expected.

@kjurl
Copy link
Author

kjurl commented Apr 18, 2022

Thank you, I was able to reproduce the steps you told and send a desired request to the server ( and made sure I could read the files as well ) ...

Something I'd like to ask you, "the order in which I select files in the file picker" isn't the same as the order in which i recieve files on the server side code. the are arranged alphabetically according to their respective content-types. Anyway, I could keep the same order on the server while recieving files as well.

Also thanks for this awesome app ✨

@Waboodoo
Copy link
Owner

Unfortunately, the order of the files is given by the file picker, which is not part of the HTTP Shortcuts app but the Android OS (or possibly some other third-party app). As such, the files are uploaded in no particular order, and the actual order may be random or decided by the picker. There isn't an easy way to fix this, short of building a fully custom file picker into the app, but that would come with drawbacks of its own.

@kjurl
Copy link
Author

kjurl commented Apr 20, 2022

thanks for the help, I would have wanted the order of the files to persist but guess I'll work with what I've got. ik this might be a stretch, but is there a function in the js-snippets that are run before the request, which can launch the file picker and get me the file, I was against using some client side logic but guess there's no avoiding it now. if you can think of any workarounds, do suggest me some. again, thank you for your time and effort

@Waboodoo
Copy link
Owner

Unfortunately, the entire file handling is currently not accessible by the Scripting feature, or only in a read-only manner. I'm looking into extending that though, as there's also been other related feature requests and ideas floating around, e.g., this one.

For now, I don't see an easy workaround. You could create multiple single-file parameters in your shortcut, but that would mean that the number of files to be uploaded is constant, which is probably not what you want.

@Waboodoo
Copy link
Owner

The following does not directly address the issues described above, but perhaps it is helpful in some ways anyway.

With version 2.16.0, there is now the possibility to forward files that were selected in the file picker to another shortcut. It is not (yet) possible to open a file picker directly through Scripting, but you can just add a file parameter to your shortcut so that a file picker is invoked when the shortcut is triggered. You can then access the selected files via the selectedFiles JS variable, and enqueue another shortcut to use those files. You could do some forms of pre-processing on the files, e.g. sorting them alphabetically by their file names.

You'll find more information about this here: https://http-shortcuts.rmy.ch/scripting#files and https://http-shortcuts.rmy.ch/scripting#trigger-shortcut

@kjurl
Copy link
Author

kjurl commented Jul 15, 2022

sorry for the late reply ...

Using the suggested way: I will then have to manually rename each file in ascending order ... ^^"

The only possible way I see this happening is if

  1. the file picker actually stored the selection order of files, or
  2. a separate in-app window for reordering the files ( if you ever go with this option, it'll be nice to see ... an image preview, and their MIME types in the reorder menu )

thanks for your time ✨️

@Waboodoo
Copy link
Owner

  1. the file picker actually stored the selection order of files

As the file picker is not part of the app, but comes from Android itself or from another app, I have no control over it. The only way to achieve this reliably would be to build a custom file picker into the app, which would have its own drawbacks

  1. a separate in-app window for reordering the files

This would be feasible, but requires a lot of effort to build. I'll keep the idea in the backlog, but will not focus on it for now. I want to make some general improvements to how files are handled in the app, so maybe it fits in with that broader topic, but currently I have no timeline for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants