mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-15 16:10:06 +00:00
fix(*): support multipart form data post
This commit is contained in:
@@ -20,6 +20,7 @@ import { Logger, LogLevel } from '@sasjs/utils/logger'
|
|||||||
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { NotFoundError } from './types/NotFoundError'
|
import { NotFoundError } from './types/NotFoundError'
|
||||||
|
import { SasAuthResponse } from '@sasjs/utils/types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A client for interfacing with the SAS Viya REST API.
|
* A client for interfacing with the SAS Viya REST API.
|
||||||
@@ -693,7 +694,13 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const authResponse = await this.requestClient
|
const authResponse = await this.requestClient
|
||||||
.post(url, formData, undefined, 'application/json', headers)
|
.post<SasAuthResponse>(
|
||||||
|
url,
|
||||||
|
formData,
|
||||||
|
undefined,
|
||||||
|
'multipart/form-data; boundary=' + (formData as any)._boundary,
|
||||||
|
headers
|
||||||
|
)
|
||||||
.then((res) => res.result)
|
.then((res) => res.result)
|
||||||
|
|
||||||
return authResponse
|
return authResponse
|
||||||
@@ -733,7 +740,13 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const authResponse = await this.requestClient
|
const authResponse = await this.requestClient
|
||||||
.post(url, formData, undefined, 'application/json', headers)
|
.post<SasAuthResponse>(
|
||||||
|
url,
|
||||||
|
formData,
|
||||||
|
undefined,
|
||||||
|
'multipart/form-data; boundary=' + (formData as any)._boundary,
|
||||||
|
headers
|
||||||
|
)
|
||||||
.then((res) => res.result)
|
.then((res) => res.result)
|
||||||
|
|
||||||
return authResponse
|
return authResponse
|
||||||
|
|||||||
@@ -270,14 +270,16 @@ export class RequestClient implements HttpClient {
|
|||||||
accessToken: string | undefined,
|
accessToken: string | undefined,
|
||||||
contentType: string
|
contentType: string
|
||||||
) => {
|
) => {
|
||||||
const headers: any = {
|
const headers: any = {}
|
||||||
'Content-Type': contentType
|
|
||||||
|
if (contentType !== 'application/x-www-form-urlencoded') {
|
||||||
|
headers['Content-Type'] = contentType
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contentType === 'text/plain') {
|
if (contentType === 'application/json') {
|
||||||
headers.Accept = '*/*'
|
|
||||||
} else {
|
|
||||||
headers.Accept = 'application/json'
|
headers.Accept = 'application/json'
|
||||||
|
} else {
|
||||||
|
headers.Accept = '*/*'
|
||||||
}
|
}
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
|
|||||||
Reference in New Issue
Block a user