Limit R2 Uploads to Images & to not exceed size

How can I limit R2 uploads to be within a certain range or not exceed a certain value as well as only accept certain content types? I'm planning on uploading from browser using signed URLs.
3 Replies
Erisa
Erisa9mo ago
Get the client to provide the size and content type when requesting the signed url, only accept the request if those match within the intended range and then return the url with the content-length and content-type headers signed to be the values the client said they would be
jrdn
jrdnOP9mo ago
@Erisa | Support Engineer I was going to go down this path. Is there a more generic way of just creating a bucket-wide rule for this and not force application side to worry about it like S3 / AWS does? also, I'm not sure that there are attack vectors possible with content-type as I know they can be spoofed, but I'm assuming if my server generates the signed url with specific header that R2 internally is validating request headers against the headers which were signed? I'll test this later.
Erisa
Erisa9mo ago
There is not
I'm assuming if my server generates the signed url with specific header that R2 internally is validating request headers against the headers which were signed?
Correct There is nothing stopping a client from lying about a content type e.g. uploading exe as a jpg though, only thing you can guarantee is that the headers are the same
Want results from more Discord servers?
Add your server