Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
c829b06169 | |||
80fa40baf4 | |||
3659b80e1e | |||
770e7d46ea | |||
2a46f2a306 | |||
eae4d09664 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "1.1.44",
|
"version": "1.1.47",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "1.1.44",
|
"version": "1.1.47",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "dropin replacement for request",
|
"description": "dropin replacement for request",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -8,6 +8,10 @@ export const getBinary = async (
|
|||||||
domainArg: string,
|
domainArg: string,
|
||||||
optionsArg: interfaces.ISmartRequestOptions = {}
|
optionsArg: interfaces.ISmartRequestOptions = {}
|
||||||
) => {
|
) => {
|
||||||
|
optionsArg = {
|
||||||
|
...optionsArg,
|
||||||
|
autoJsonParse: false
|
||||||
|
};
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
const response = await request(domainArg, optionsArg, true);
|
const response = await request(domainArg, optionsArg, true);
|
||||||
const data = [];
|
const data = [];
|
||||||
@ -21,7 +25,7 @@ export const getBinary = async (
|
|||||||
//so Buffer.concat() can make us a new Buffer
|
//so Buffer.concat() can make us a new Buffer
|
||||||
//of all of them together
|
//of all of them together
|
||||||
const buffer = Buffer.concat(data);
|
const buffer = Buffer.concat(data);
|
||||||
response.body = buffer.toString('binary');
|
response.body = buffer;
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
await done.promise;
|
await done.promise;
|
||||||
|
@ -10,6 +10,7 @@ export interface IFormField {
|
|||||||
type: 'string' | 'filePath' | 'Buffer';
|
type: 'string' | 'filePath' | 'Buffer';
|
||||||
payload: string | Buffer;
|
payload: string | Buffer;
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
|
contentType?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const appendFormField = async (formDataArg: plugins.formData, formDataField: IFormField) => {
|
const appendFormField = async (formDataArg: plugins.formData, formDataField: IFormField) => {
|
||||||
@ -34,9 +35,9 @@ const appendFormField = async (formDataArg: plugins.formData, formDataField: IFo
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'Buffer':
|
case 'Buffer':
|
||||||
formDataArg.append('file', formDataField.payload, {
|
formDataArg.append(formDataField.name, formDataField.payload, {
|
||||||
filename: formDataField.fileName ? formDataField.fileName : 'upload.pdf',
|
filename: formDataField.fileName ? formDataField.fileName : 'upload.pdf',
|
||||||
contentType: 'application/pdf'
|
contentType: formDataField.contentType ? formDataField.contentType : 'application/pdf'
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user