From 1802870b898c9668cbc90ef8e343bfb412ec9a53 Mon Sep 17 00:00:00 2001 From: Tenn Chio Date: Fri, 25 Nov 2022 14:06:30 +0800 Subject: [PATCH] docs: binary response in vite env --- docs/recipes/binary-response-type.mdx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/recipes/binary-response-type.mdx b/docs/recipes/binary-response-type.mdx index e80aac96..b125de8e 100644 --- a/docs/recipes/binary-response-type.mdx +++ b/docs/recipes/binary-response-type.mdx @@ -12,10 +12,15 @@ Here is an example of a mocked response that sends a local image: ```js showLineNumbers focusedLines=6-9,12-15 import { setupWorker, rest } from 'msw' +// Vite +import xlsxUrl froom './excel/template.xlsx?url' +// Webpack import base64Image from '!url-loader!../fixtures/image.jpg' const worker = setupWorker( rest.get('/images/:imageId', async (_, res, ctx) => { + // Convert xlsx file to "ArrayBuffer" + const xlsxBuffer = await fetch(xlsxUrl).then((res) => res.arrayBuffer()) // Convert "base64" image to "ArrayBuffer". const imageBuffer = await fetch(base64Image).then((res) => res.arrayBuffer(),