Im trying to figure out how to extract a file from a static resource. the static resource is zipped and contains a csv file. Im new with lwc, i have some experience with apex but i'm not a master.
I've been able to get the data from the csv by importing an unzipped version of the document with no trouble. the reason i'm using a zip file is so that i can include more csv files and pull the data as needed in my lightning component.
regarding the zip extraction. i've tried using apex which sort of works, i am able to select the body into a blob and then cast that data to a string after encoding it but what i get is an encrypted string. when i try to decode the string my data doesn't get passed to my lightning component.
regarding lwc i am able to import that static resource but all i can seem to get is a link to the files instead of the actual data in them.
Ive looked for a couple of days now and cant find anything that seems to work.
Is it possible to get usable data from a zipped csv file (static resource) via apex or some other method that's native to Salesforce?
Do you think i could ship the file to lwc and then use js to extract the files and store the string data in a local db or something like that?
Here is my code for the blob try. (i get the following log error as expected FATAL_ERROR System.StringException: BLOB is not a valid UTF-8 string)
//apex side
@AuraEnabled(cacheable=true)
public static String loadInterviewFile(String currentInterview){
String queryCurrentInterview = 'select id,body, name from StaticResource Where Name = \''+currentInterview +'\'';
StaticResource srObject = Database.query(queryCurrentInterview);
blob tempBlob = srObject.Body;
string s = EncodingUtil.base64Encode(tempBlob);
return EncodingUtil.base64Decode(s).toString();
//lwc side
import { LightningElement, api , track, wire} from 'lwc';
import getInterviewData from '@salesforce/apex/Core.loadInterviewFile';
export default class ListItem extends LightningElement {
@api interviewFileName;
@track interviewData;
@wire(getInterviewData , { currentInterview: '$interviewFileName' })
InterviewDataRaw({ error, data }) {
if (data) {
this.data = data;
this.error = undefined;
} else if (error) {
this.error = error;
this.data = undefined;
}
this.interviewData = this.data;
console.log('Interview Resource data ' + this.interviewData);
}
}
Any guidance you might have would be really appreciated.
Thanks