如果要将数据导出为 csv 文件,然后将其存储在 azure storage blob 中,则有两个步骤。
- 将数据导出为 CSV 文件,但不要下载
参考代码here。有官方document关于angular7-csv。
dtHolidays :any;
csvOptions = {
fieldSeparator: ',',
quoteStrings: '"',
decimalseparator: '.',
showLabels: true,
showTitle: true,
title: 'Your Holiday List :',
useBom: true,
noDownload: true, //If true, disables automatic download and returns only formatted CSV
headers: ["Holiday ID", "Holiday Date", "Holiday Comment", "Holiday Status"]
};
ngOnInit() {
//Your data for download in csv file.
this.dtHolidays =[
{"id": 101, "Holiday_Date": "21/02/2019", "Holiday_Comment": "company holiday calendar of 2019. ", "Holiday_Status": "Active"}
];
}
formatCSV(){
//this.dtHolidays : DATA , HolidayList : CSV file Name, this.csvOptions : file options
new AngularCsv(this.dtHolidays, "HolidayList", this.csvOptions);
}
- 将文件上传到 Azure 存储 blob
这是上传文件到Azure Storage的函数,参考sample。
public async uploadBlobToStorage (file: File): Promise {
const anonymousCredential = new AnonymousCredential();
const pipeline = StorageURL.newPipeline(anonymousCredential);
const serviceURL = new ServiceURL(
`PASTE BLOB SERVICE SAS URL HERE`,
pipeline
);
const containerName = "files";
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
const blobName = `${file.name}-${new Date().getTime()}`
const blobUrl = BlobURL.fromContainerURL(containerURL, blobName);
const blockblobURL = BlockBlobURL.fromBlobURL(blobUrl);
const options = {blockSize: this.getBlockSize(file), parallelism: 10, progress: (transferProgressEvent: TransferProgressEvent) => {
this.onProgressChanged(transferProgressEvent, file, this._uploadProgressSource);
} };
const blobUploadCommonResponse = await uploadBrowserDataToBlockBlob(Aborter.none, file, blockblobURL,options);
return blobUploadCommonResponse;
}