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

View file

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