-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Adding data to multipart request not from file #1028
Comments
It does seem useful to make it possible to generate that format. I have an implementation that I will submit in a pull request. As it requires a new (though backwards-compatible) API for |
jeremyevans
added a commit
to jeremyevans/rack
that referenced
this issue
Jan 17, 2020
This changes the UploadedFile API to use keyword arguments, being backwards compatible with the previous API by keeping the positional arguments and making the keyword defaults be the positional argument values. The two new arguments to UploadedFile#initialize are filename and io. filename allows overriding the filename that will be used, instead of always using the base name of the path. io specifies an IO-like object that can be read from to get the data, overridding any provided path. This allows you to generate UploadedFile instances that previously were not possible without accessing the file system. This changes the multipart generator to only include a Content-Length for files with paths, and only include a filename in Content-Disposition if the UploadedFile has one. Fixes rack#1028.
ioquatix
pushed a commit
that referenced
this issue
Jan 17, 2020
This changes the UploadedFile API to use keyword arguments, being backwards compatible with the previous API by keeping the positional arguments and making the keyword defaults be the positional argument values. The two new arguments to UploadedFile#initialize are filename and io. filename allows overriding the filename that will be used, instead of always using the base name of the path. io specifies an IO-like object that can be read from to get the data, overridding any provided path. This allows you to generate UploadedFile instances that previously were not possible without accessing the file system. This changes the multipart generator to only include a Content-Length for files with paths, and only include a filename in Content-Disposition if the UploadedFile has one. Fixes #1028.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been working using Rack to submit multipart requests to the Apple News API. This works fine when just submitting data from a JSON file, but there are cases in which an additional
metadata
part is required and is not expected to have thefilename
field in theContent-Disposition
header. Here is the example from the Apple News Documentation:The issue that I was running into when using
Multipart::build_multipart
is that it if there is nooriginal_filename
attribute, then it usesGenerator#content_for_other
to create this part of the request, which does not specifyContent-Type
(lines 83-90 of multipart/generator.rb). If I were to use a file (or file like object) and build this with Multipart::UploadedFile, then the filename is included in theContent-Disposition
, which I do not want.What I was hoping to see (and I'd be willing to help contribute to) is a class similar to
Multipart::UploadedFile
that instead of receiving the path to a file upon initialization could simply receive a string of the content, and corresponding changes toMultipart::Generator
that would allow for an instance of this class to be passed to the generator and build the part of the request correctly.I'm not sure if this is an issue with other APIs that expect multipart requests, but for the Apple News API there are several different metadata fields that we will need to be submitting, so this functionality would be very useful. Thanks for all the hard work on Rack and let me know if I can provide any clarification or help make these changes.
The text was updated successfully, but these errors were encountered: