companion,xhr-upload: option to set multipart http method

fixes #2019 (we can all go one year backwards once this is merged)
This commit is contained in:
ifedapoolarewaju 2020-01-31 15:51:15 +01:00
parent 746bbcbbc5
commit 4ed7508f78
No known key found for this signature in database
GPG key ID: FF050AA4EEBCE82E
2 changed files with 5 additions and 1 deletions

View file

@ -36,6 +36,7 @@ class Uploader {
* @property {any} companionOptions
* @property {any=} storage
* @property {any=} headers
* @property {string=} httpMethod
*
* @param {UploaderOptions} options
*/
@ -112,6 +113,7 @@ class Uploader {
uploadUrl: req.body.uploadUrl,
protocol: req.body.protocol,
metadata: req.body.metadata,
httpMethod: req.body.httpMethod,
size: size,
fieldname: req.body.fieldname,
pathPrefix: `${req.companion.options.filePath}`,
@ -455,8 +457,9 @@ class Uploader {
}
}
)
const httpMethod = (this.options.httpMethod || '').toLowerCase() === 'put' ? 'put' : 'post'
const headers = headerSanitize(this.options.headers)
request.post({ url: this.options.endpoint, headers, formData, encoding: null }, (error, response, body) => {
request[httpMethod]({ url: this.options.endpoint, headers, formData, encoding: null }, (error, response, body) => {
if (error) {
logger.error(error, 'upload.multipart.error')
this.emitError(error)

View file

@ -356,6 +356,7 @@ module.exports = class XHRUpload extends Plugin {
size: file.data.size,
fieldname: opts.fieldName,
metadata: fields,
httpMethod: this.opts.method,
headers: opts.headers
}).then((res) => {
const token = res.token