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

Add support for filename, content-type and headers when uploading files #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

filbranden
Copy link

The requests library has support for passing additional information, such as the intended filename on upload, the content-type and additional headers, by passing a tuple with 2, 3 or 4 elements instead of just a file object.

See "POST a Multipart-Encoded File" in the requests documentation for more details:
https://requests.readthedocs.io/en/latest/user/quickstart/#post-a-multipart-encoded-file

Extend aptly_api files API to also be able to take similar tuples when uploading files to Aptly.

One useful use case is to pass a proper package filename, in cases where packages are generated simply as <name>.deb by upstream projects (usually via non native Debian build systems) but should more properly be stored as <name>_<epoch>:<version>_<arch>.deb. Renaming files locally is a possibility, but potentially runs into permission issues. Being able to specify the filename to the API solves this in a more elegant way, without having to modify the local filesystem. The package information can be easily derived using debian.debfile.DebFile() to inspect a package file, in specific gencontrol() returns the fields of the control file which can be used to derive the expected filename.

Tested locally by uploading files to aptly using the modified API. Also added a test (even though it mostly relies on mocks.) Confirmed mypy is happy with all the type annotation.

The requests library has support for passing additional information,
such as the intended filename on upload, the content-type and additional
headers, by passing a tuple with 2, 3 or 4 elements instead of just a
file object.

See "POST a Multipart-Encoded File" in requests documentation for details:
https://requests.readthedocs.io/en/latest/user/quickstart/#post-a-multipart-encoded-file

Extend aptly_api files API to also be able to take similar tuples when
uploading files to Aptly.

One useful use case is to pass a proper package filename, in cases where
packages are generated simply as <name>.deb by upstream projects
(usually via non native Debian build systems) but should more properly
be stored as <name>_<epoch>:<version>_<arch>.deb. Renaming files locally
is a possibility, but potentially runs into permission issues. Being
able to specify the filename to the API solves this in a more elegant
way, without having to modify the local filesystem. The package
information can be easily derived using debian.debfile.DebFile() to
inspect a package file, in specific gencontrol() returns the fields of
the control file which can be used to derive the expected filename.

Tested locally by uploading files to aptly using the modified API. Also
added a test (even though it mostly relies on mocks.) Confirmed mypy is
happy with all the type annotation.
@filbranden
Copy link
Author

@jdelic would you kindly take a look? Thanks!

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

Successfully merging this pull request may close these issues.

1 participant