diff --git a/src/main/minio.js b/src/main/minio.js index 1d035aba..8ba6856c 100644 --- a/src/main/minio.js +++ b/src/main/minio.js @@ -3665,6 +3665,15 @@ export class PostPolicy { this.formData['Content-Type'] = type } + // set Content-Type prefix, i.e image/ allows any image + setContentTypeStartsWith(prefix) { + if (!prefix) { + throw new Error('content-type cannot be null') + } + this.policy.conditions.push(['starts-with', '$Content-Type', prefix]) + this.formData['Content-Type'] = prefix + } + // set minimum/maximum length of what Content-Length can be. setContentLengthRange(min, max) { if (min > max) { diff --git a/src/test/functional/functional-tests.js b/src/test/functional/functional-tests.js index bb2e3f35..bfcae27d 100644 --- a/src/test/functional/functional-tests.js +++ b/src/test/functional/functional-tests.js @@ -1063,6 +1063,44 @@ describe('functional tests', function () { }) }) + step('presignedPostPolicy(postPolicy, cb)_postPolicy:setContentType', done => { + var policy = client.newPostPolicy() + policy.setKey(_1byteObjectName) + policy.setBucket(bucketName) + policy.setContentType('text/plain') + + client.presignedPostPolicy(policy, (e, data) => { + if (e) return done(e) + var req = superagent.post(data.postURL) + _.each(data.formData, (value, key) => req.field(key, value)) + req.attach('file', Buffer.from([_1byte]), 'test') + req.end(function(e) { + if (e) return done(e) + done() + }) + req.on('error', e => done(e)) + }) + }) + + step('presignedPostPolicy(postPolicy, cb)_postPolicy:setContentTypeStartsWith', done => { + var policy = client.newPostPolicy() + policy.setKey(_1byteObjectName) + policy.setBucket(bucketName) + policy.setContentTypeStartsWith('text/') + + client.presignedPostPolicy(policy, (e, data) => { + if (e) return done(e) + var req = superagent.post(data.postURL) + _.each(data.formData, (value, key) => req.field(key, value)) + req.attach('file', Buffer.from([_1byte]), 'test') + req.end(function(e) { + if (e) return done(e) + done() + }) + req.on('error', e => done(e)) + }) + }) + step('presignedPostPolicy(postPolicy)_postPolicy: null_', done => { client.presignedPostPolicy(null) .then(() => {