后端代码
func (a *App) Greet(name string) ([]byte, error) {
pdfData, err := ioutil.ReadFile(".//aaa.pdf")
if err != nil {
return nil, err
}
return pdfData, nil
}
前端代码
const fetchBlob = async () => {
try {
const pdfData = await Greet('aaa');
const blob = new Blob([pdfData], { type: 'application/pdf' });
console.log(blob)
const url = URL.createObjectURL(blob);
setBlobUrl(url);
} catch (error) {
console.error('Error fetching blob:', error);
}
};