Skip to content

Commit 059247a

Browse files
committed
Adjust uploadDataBlob to expose more options
Signed-off-by: Andrew Richardson <[email protected]>
1 parent 3e0438b commit 059247a

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

lib/firefly.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ import {
6565
FireFlyGroupResponse,
6666
FireFlyBlockchainEventFilter,
6767
FireFlyBlockchainEventResponse,
68+
FireFlyDataBlobRequest,
69+
FireFlyDataBlobRequestDefaults,
6870
} from './interfaces';
6971
import { FireFlyWebSocket, FireFlyWebSocketCallback } from './websocket';
7072
import HttpBase, { mapConfig } from './http';
@@ -196,25 +198,18 @@ export default class FireFly extends HttpBase {
196198

197199
async uploadDataBlob(
198200
blob: string | Buffer | Readable,
199-
filename: string,
201+
blobOptions?: FormData.AppendOptions,
202+
dataOptions?: FireFlyDataBlobRequest,
200203
): Promise<FireFlyDataResponse> {
204+
dataOptions = { ...FireFlyDataBlobRequestDefaults, ...dataOptions };
201205
const formData = new FormData();
202-
formData.append('autometa', 'true');
203-
formData.append('file', blob, { filename });
204-
const response = await this.wrapError(
205-
this.http.post<FireFlyDataResponse>('/data', formData, {
206-
headers: {
207-
...formData.getHeaders(),
208-
'Content-Length': formData.getLengthSync(),
209-
},
210-
}),
211-
);
212-
return response.data;
213-
}
214-
215-
async uploadDataBlobWithFormData(
216-
formData: FormData
217-
): Promise<FireFlyDataResponse> {
206+
for (const key in dataOptions) {
207+
const val = dataOptions[key as keyof FireFlyDataBlobRequest];
208+
if (val !== undefined) {
209+
formData.append(key, val);
210+
}
211+
}
212+
formData.append('file', blob, blobOptions);
218213
const response = await this.wrapError(
219214
this.http.post<FireFlyDataResponse>('/data', formData, {
220215
headers: {

lib/interfaces.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,17 @@ export type FireFlyDataFilter = operations['getData']['parameters']['query'];
159159

160160
export type FireFlyDataRequest =
161161
operations['postData']['requestBody']['content']['application/json'];
162+
export type FireFlyDataBlobRequest =
163+
operations['postData']['requestBody']['content']['multipart/form-data'];
162164

163165
export type FireFlyDataResponse = Required<
164166
operations['getDataByID']['responses']['200']['content']['application/json']
165167
>;
166168

169+
export const FireFlyDataBlobRequestDefaults: FireFlyDataBlobRequest = {
170+
autometa: 'true',
171+
};
172+
167173
// Messages
168174

169175
export type FireFlyMessageFilter = operations['getMsgs']['parameters']['query'];

0 commit comments

Comments
 (0)