new(basic.gblib): #394 UPLOAD keyword.
This commit is contained in:
parent
3fa89851d2
commit
10871af6ca
1 changed files with 93 additions and 84 deletions
|
@ -69,7 +69,8 @@ import {
|
||||||
BlobServiceClient,
|
BlobServiceClient,
|
||||||
BlockBlobClient,
|
BlockBlobClient,
|
||||||
ContainerClient,
|
ContainerClient,
|
||||||
StoragePipelineOptions
|
StoragePipelineOptions,
|
||||||
|
StorageSharedKeyCredential
|
||||||
} from '@azure/storage-blob';
|
} from '@azure/storage-blob';
|
||||||
|
|
||||||
import { md5 } from 'js-md5';
|
import { md5 } from 'js-md5';
|
||||||
|
@ -672,29 +673,37 @@ export class SystemKeywords {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = GBServer.globals.files[data].data;
|
data = GBServer.globals.files[data].data;
|
||||||
|
const accountName = min.getParam('Blob Account');
|
||||||
|
const accountKey = min.getParam('Blob Key');
|
||||||
const blobName = min.getParam('Blob Name');
|
const blobName = min.getParam('Blob Name');
|
||||||
const connString = min.getParam('Blob ConnectionString');
|
const sharedKeyCredential = new StorageSharedKeyCredential(
|
||||||
const containerName = min.getParam('Blob Container Name');
|
accountName,
|
||||||
const storagePipelineOptions: StoragePipelineOptions = {};
|
accountKey
|
||||||
|
|
||||||
const client: BlobServiceClient = BlobServiceClient.fromConnectionString(
|
|
||||||
connString,
|
|
||||||
storagePipelineOptions
|
|
||||||
);
|
);
|
||||||
const container = client.getContainerClient(containerName);
|
const baseUrl = `https://${accountName}.blob.core.windows.net`;
|
||||||
|
|
||||||
|
const blobServiceClient = new BlobServiceClient(
|
||||||
|
`${baseUrl}`,
|
||||||
|
sharedKeyCredential
|
||||||
|
);
|
||||||
|
const container = blobServiceClient.getContainerClient(accountName);
|
||||||
|
const hash = new Uint8Array(md5.array(data));
|
||||||
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(blobName);
|
const blockBlobClient: BlockBlobClient = container.getBlockBlobClient(blobName);
|
||||||
|
|
||||||
const hash = new Uint8Array(md5.array(data));
|
const res = await blockBlobClient.uploadFile(data.filename,
|
||||||
|
{
|
||||||
await blockBlobClient.uploadFile(data.filename,
|
blobHTTPHeaders: {
|
||||||
{blobHTTPHeaders:{
|
blobContentMD5: hash
|
||||||
blobContentMD5:hash}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res._response.status===200 && res.contentMD5 === hash) {
|
||||||
const tmpFile = '';
|
const tmpFile = '';
|
||||||
await blockBlobClient.downloadToFile(tmpFile);
|
|
||||||
|
|
||||||
Fs.rmSync(tmpFile);
|
Fs.rmSync(tmpFile);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
GBLog.error(`BASIC: BLOB HTTP ${res.errorCode} ${res._response.status} .`);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1659,7 +1668,7 @@ export class SystemKeywords {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getCustomToken({pid, token}) :Promise<string>{
|
public async getCustomToken({ pid, token }): Promise<string> {
|
||||||
|
|
||||||
const { min } = await DialogKeywords.getProcessInfo(pid);
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `GET TOKEN: ${token}`);
|
GBLogEx.info(min, `GET TOKEN: ${token}`);
|
||||||
|
@ -2361,8 +2370,8 @@ export class SystemKeywords {
|
||||||
|
|
||||||
// In case of storage, persist to DB in batch.
|
// In case of storage, persist to DB in batch.
|
||||||
|
|
||||||
if (fieldsValuesList.length){
|
if (fieldsValuesList.length) {
|
||||||
await this.saveToStorageBatch({ pid, table: file, rows:fieldsValuesList });
|
await this.saveToStorageBatch({ pid, table: file, rows: fieldsValuesList });
|
||||||
}
|
}
|
||||||
|
|
||||||
GBLog.info(`BASIC: MERGE updated (merges:${merges}, additions:${adds}, skipped: ${skipped}).`);
|
GBLog.info(`BASIC: MERGE updated (merges:${merges}, additions:${adds}, skipped: ${skipped}).`);
|
||||||
|
|
Loading…
Add table
Reference in a new issue