import * as fs from "fs" ; import { toQueryString } from "../../utils" ; import { fileUploadOptionalParameters , MultipartUploader } from "../common/multipart-uploader" ; import { SdkClient } from "../common/sdk-client" ; import { IotFileModels } from "./iot-file-models" ; export class extends SdkClient export class IotFileClient extends SdkClient { private _baseUrl : string = "/api/iotfile/v3" ; param { string } entityId param { string } filepath param { ( string | Buffer ) } file param { { part ? : number ; ifMatch : number ; timestamp ? : Date ; description ? : string ; type ? : string } } params returns { Promise < Headers > } memberOf public async PutFile ( entityId , filepath , file , params ? ) { const myBuffer = typeof file === "string" ? fs . readFileSync ( file ) : ( file as Buffer ) ; const parameters = params || { } ; return ( await this . HttpAction ( { verb : "PUT" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : `${ this . _baseUrl }/files/${ entityId }/${ filepath }` , body : myBuffer , additionalHeaders : parameters , octetStream : true , noResponse : true , returnHeaders : true } ) ) as Headers ; } param { string } entityId param { string } filepath param { ( string | Buffer ) } file param { { ifNoneMatch ? : number ; range ? : string } } params param { number | undefined } params . ifNoneMatch param { number | undefined } params . ifNoneMatch returns { Promise < Response > } memberOf public async GetFile ( entityId , filepath , params ? ) { const parameters = params || { } ; return ( await this . HttpAction ( { verb : "GET" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : `${ this . _baseUrl }/files/${ entityId }/${ filepath }` , additionalHeaders : parameters , rawResponse : true } ) ) as Response ; } param { string } entityid param { { offset ? : number ; limit ? : number ; count ? : number ; order ? : string ; filter ? : string } } params returns { Promise < IotFileModels . File [ ] > } memberOf public async GetFiles ( entityid , params ? ) { const parameters = params || { } ; const { offset , limit , count , order , filter } = parameters ; return ( await ( this . HttpAction ( { verb : "GET" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : `${ this . _baseUrl }/files/${ entityid }?${ toQueryString ( { filter , offset , limit , count , order } ) }` } ) as unknown ) ) as IotFileModels . File [ ] ; } param { string } entityId param { string } filepath returns memberOf public async DeleteFile ( entityId , filepath ) { return await this . HttpAction ( { verb : "DELETE" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : `${ this . _baseUrl }/files/${ entityId }/${ filepath }` , noResponse : true } ) ; } param { string } entityId param { string } filepath returns memberOf public async GetMultipartUploads ( entityId , filepath ) { return await this . HttpAction ( { verb : "GET" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : `${ this . _baseUrl }/fileslist/${ entityId }/${ filepath }` } ) ; } param { string } entityId param { string } filepath param { ( string | Buffer ) } file param { fileUploadOptionalParameters } params param { ( number | undefined ) } params . part param { ( Date | undefined ) } params . timestamp param { ( string | undefined ) } params . description param { ( string | undefined ) } params . type param { ( number | undefined ) } params . chunkSize param { ( number | undefined ) } params . retry param { ( Function | undefined ) } params . logFunction param { ( Function | undefined ) } params . verboseFunction param { ( boolean | undefined ) } params . chunk param { ( number | undefined ) } params . parallelUploads param { ( number | undefined ) } params . ifMatch returns { Promise < string > } example example memberOf public async UploadFile ( entityId , filepath , file , params ? ) { const result = await this . uploader . UploadFile ( entityId , filepath , file , params ) ; return result ; } param { string } entityId param { string } filePath memberOf public async AbortUpload ( entityId , filePath ) { await this . uploader . AbortUpload ( entityId , filePath ) ; } private uploader = new MultipartUploader ( undefined , this ) ; }