Skip to content

add min-len and max-len parameters to mc share upload #5184

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

devnewton
Copy link

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers
under the terms of the Apache 2 license.
By creating this pull request I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 license.

Description

Allow to specify content length range with mc share upload command.

Motivation and Context

This is usefull to share upload link with length restriction.

This feature is already present in minio java client.

How to test this PR?

Create a test bucket on play server and share an upload using --max-len parameter then upload a file larger than expected:

mc mb play/mytest
mc share upload --max-len 2 play/mytest/info.txt
curl (...) -Ffile=@afilebiggerthantwobytes.txt

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Optimization (provides speedup with no functional changes)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Unit tests added/updated => I'm dont know how to do this for this kind feature :-(
  • Internal documentation updated
  • Create a documentation update request here => I've updated the cli help. I will create the documentation update if this pull request is accepted.

@shtripat
Copy link
Contributor

shtripat commented Apr 3, 2025

max-len setting seems working but min-len doesn't seems be working as expected

$ mc mb play/shubhendu-bkt2
Bucket created successfully `play/shubhendu-bkt2`.

$ echo "hello" > info.txt
 
$ ls -lrt info.txt
-rw-r--r-- 1 shubhendu shubhendu 6 Apr  3 21:29 info.txt

$ ./mc share upload --min-len 2048 play/shubhendu-bkt2/info.txt
URL: https://play.min.io/shubhendu-bkt2/info.txt
Expire: 7 days 0 hours 0 minutes 0 seconds
Share: curl https://play.min.io/shubhendu-bkt2/ -F policy=eyJleHBpcmF0aW9uIjoiMjAyNS0wNC0xMFQxNjowMDoyNS42MjRaIiwiY29uZGl0aW9ucyI6W1siZXEiLCIkYnVja2V0Iiwic2h1YmhlbmR1LWJrdDIiXSxbImVxIiwiJGtleSIsImluZm8udHh0Il0sWyJlcSIsIiR4LWFtei1kYXRlIiwiMjAyNTA0MDNUMTYwMDI2WiJdLFsiZXEiLCIkeC1hbXotYWxnb3JpdGhtIiwiQVdTNC1ITUFDLVNIQTI1NiJdLFsiZXEiLCIkeC1hbXotY3JlZGVudGlhbCIsIlEzQU0zVVE4NjdTUFFRQTQzUDJGLzIwMjUwNDAzL3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QiXV19 -F x-amz-algorithm=AWS4-HMAC-SHA256 -F x-amz-credential=Q3AM3UQ867SPQQA43P2F/20250403/us-east-1/s3/aws4_request -F x-amz-date=20250403T160026Z -F x-amz-signature=07c24ea645ad9b2d0bf1eb082438d0dccedded0641a4ce2a41696936b935ba25 -F bucket=shubhendu-bkt2 -F key=info.txt -F file=@<FILE>

$ curl https://play.min.io/shubhendu-bkt2/ -F policy=eyJleHBpcmF0aW9uIjoiMjAyNS0wNC0xMFQxNjowMDoyNS42MjRaIiwiY29uZGl0aW9ucyI6W1siZXEiLCIkYnVja2V0Iiwic2h1YmhlbmR1LWJrdDIiXSxbImVxIiwiJGtleSIsImluZm8udHh0Il0sWyJlcSIsIiR4LWFtei1kYXRlIiwiMjAyNTA0MDNUMTYwMDI2WiJdLFsiZXEiLCIkeC1hbXotYWxnb3JpdGhtIiwiQVdTNC1ITUFDLVNIQTI1NiJdLFsiZXEiLCIkeC1hbXotY3JlZGVudGlhbCIsIlEzQU0zVVE4NjdTUFFRQTQzUDJGLzIwMjUwNDAzL3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QiXV19 -F x-amz-algorithm=AWS4-HMAC-SHA256 -F x-amz-credential=Q3AM3UQ867SPQQA43P2F/20250403/us-east-1/s3/aws4_request -F x-amz-date=20250403T160026Z -F x-amz-signature=07c24ea645ad9b2d0bf1eb082438d0dccedded0641a4ce2a41696936b935ba25 -F bucket=shubhendu-bkt2 -F key=info.txt -F file=@info.txt

$ mc ls play/shubhendu-bkt2 
[2025-04-03 21:30:39 IST]     6B STANDARD info.txt

expected curl upload to fail as upload size if 6B and min-len was set as 2048

@devnewton
Copy link
Author

I forgot to check the error returned by SetContentLengthRange. It ensures than min-len is smaller than max-len.

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.

2 participants