@@ -65,6 +65,8 @@ import {
65
65
FireFlyGroupResponse ,
66
66
FireFlyBlockchainEventFilter ,
67
67
FireFlyBlockchainEventResponse ,
68
+ FireFlyDataBlobRequest ,
69
+ FireFlyDataBlobRequestDefaults ,
68
70
} from './interfaces' ;
69
71
import { FireFlyWebSocket , FireFlyWebSocketCallback } from './websocket' ;
70
72
import HttpBase , { mapConfig } from './http' ;
@@ -190,27 +192,24 @@ export default class FireFly extends HttpBase {
190
192
return this . createOne < FireFlyDataResponse > ( '/data' , data , options ) ;
191
193
}
192
194
195
+ publishData ( id : string , options ?: FireFlyCreateOptions ) : Promise < FireFlyDataResponse > {
196
+ return this . createOne < FireFlyDataResponse > ( `/data/${ id } /value/publish` , { } , options ) ;
197
+ }
198
+
193
199
async uploadDataBlob (
194
200
blob : string | Buffer | Readable ,
195
- filename : string ,
201
+ blobOptions ?: FormData . AppendOptions ,
202
+ dataOptions ?: FireFlyDataBlobRequest ,
196
203
) : Promise < FireFlyDataResponse > {
204
+ dataOptions = { ...FireFlyDataBlobRequestDefaults , ...dataOptions } ;
197
205
const formData = new FormData ( ) ;
198
- formData . append ( 'autometa' , 'true' ) ;
199
- formData . append ( 'file' , blob , { filename } ) ;
200
- const response = await this . wrapError (
201
- this . http . post < FireFlyDataResponse > ( '/data' , formData , {
202
- headers : {
203
- ...formData . getHeaders ( ) ,
204
- 'Content-Length' : formData . getLengthSync ( ) ,
205
- } ,
206
- } ) ,
207
- ) ;
208
- return response . data ;
209
- }
210
-
211
- async uploadDataBlobWithFormData (
212
- formData : FormData
213
- ) : 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 ) ;
214
213
const response = await this . wrapError (
215
214
this . http . post < FireFlyDataResponse > ( '/data' , formData , {
216
215
headers : {
@@ -222,13 +221,8 @@ export default class FireFly extends HttpBase {
222
221
return response . data ;
223
222
}
224
223
225
- async publishDataBlobToSharedStorage (
226
- dataid : string
227
- ) : Promise < FireFlyDataResponse > {
228
- const response = await this . wrapError (
229
- this . http . post < FireFlyDataResponse > ( `/data/${ dataid } /blob/publish` , { dataid} ) ,
230
- ) ;
231
- return response . data ;
224
+ publishDataBlob ( id : string , options ?: FireFlyCreateOptions ) : Promise < FireFlyDataResponse > {
225
+ return this . createOne < FireFlyDataResponse > ( `/data/${ id } /blob/publish` , { } , options ) ;
232
226
}
233
227
234
228
getBatches (
0 commit comments