Update FileUpload ContentType

This commit is contained in:
Frank Jogeleit 2021-01-24 13:52:05 +01:00
parent b6bb4fa030
commit 42677b964e
4 changed files with 24 additions and 13 deletions

View file

@ -11,7 +11,6 @@ inputs:
contentType:
description: 'Content Type'
required: false
default: 'application/json'
data:
description: 'Request Body as JSON String'
required: false

18
dist/index.js vendored
View file

@ -1342,8 +1342,6 @@ const METHOD_POST = 'POST'
const request = async({ method, instanceConfig, data, files, auth, actions, preventFailureOnNoResponse, escapeData }) => {
try {
const instance = axios.create(instanceConfig);
if (escapeData) {
data = data.replace(/"[^"]*"/g, (match) => {
return match.replace(/[\n\r]\s*/g, "\\n");
@ -1375,6 +1373,10 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
data
}
actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const instance = axios.create(instanceConfig);
actions.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
@ -1421,12 +1423,18 @@ const convertToFormData = (data, files) => {
const updateConfig = async (instanceConfig, formData, actions) => {
try {
const formHeaders = formData.getHeaders()
const contentType = formHeaders['content-type']
delete formHeaders['content-type']
return {
...instanceConfig,
headers: {
...instanceConfig.headers,
...formData.getHeaders(),
'Content-Length': await contentLength(formData)
...formHeaders,
'Content-Length': await contentLength(formData),
'Content-Type': contentType
}
}
} catch(error) {
@ -3561,8 +3569,6 @@ const instanceConfig = {
headers: { ...headers, ...customHeaders }
}
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const data = core.getInput('data') || '{}';
const files = core.getInput('files') || '{}';
const method = core.getInput('method') || METHOD_POST;

View file

@ -7,8 +7,6 @@ const METHOD_POST = 'POST'
const request = async({ method, instanceConfig, data, files, auth, actions, preventFailureOnNoResponse, escapeData }) => {
try {
const instance = axios.create(instanceConfig);
if (escapeData) {
data = data.replace(/"[^"]*"/g, (match) => {
return match.replace(/[\n\r]\s*/g, "\\n");
@ -40,6 +38,10 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
data
}
actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const instance = axios.create(instanceConfig);
actions.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
@ -86,12 +88,18 @@ const convertToFormData = (data, files) => {
const updateConfig = async (instanceConfig, formData, actions) => {
try {
const formHeaders = formData.getHeaders()
const contentType = formHeaders['content-type']
delete formHeaders['content-type']
return {
...instanceConfig,
headers: {
...instanceConfig.headers,
...formData.getHeaders(),
'Content-Length': await contentLength(formData)
...formHeaders,
'Content-Length': await contentLength(formData),
'Content-Type': contentType
}
}
} catch(error) {

View file

@ -34,8 +34,6 @@ const instanceConfig = {
headers: { ...headers, ...customHeaders }
}
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const data = core.getInput('data') || '{}';
const files = core.getInput('files') || '{}';
const method = core.getInput('method') || METHOD_POST;