I'm trying to download a pdf file using arraybuffer type. I have already done this on JavaScript, but I'm trying to change the project to TypeScript and I'm having problems. I think the problem is something about the 'arraybuffer' type, as I there was a "Type '"arraybuffer"' is not assignable to type 'ResponseType'" message before. But I have already tried some things from here and here and I still can't make it work.
Right now I'm using:
const req:any = { responseType: "arraybuffer" as const};
const { get } = useRequest(undefined, req.responseType );
Although Visual Studio does not acuses error anymore, I'm still getting the same kind of response:
%??ü?
1 0 obj
<<
/Type /Catalog
/Version /1.4
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [3 0 R 4 0 R 5 0 R]
/Count 3
>>
endobj
3 0 obj
<<
/Type /Page
/MediaBox [0.0 0.0 612.0 792.0]
/Parent 2 0 R
/Contents 6 0 R
/Resources 7 0 R
>>
endobj
4 0 obj
<<
/Type /Page
/MediaBox [0.0 0.0 612.0 792.0]
/Parent 2 0 R
/Contents 8 0 R
/Resources 9 0 R
>>
endobj
5 0 obj
<<
/Type /Page
/MediaBox [0.0 0.0 612.0 792.0]
/Parent 2 0 R
/Contents 10 0 R
/Resources 11 0 R
>>
endobj
6 0 obj
<<
/Length 1103
/Filter /FlateDecode
>>
stream
xíWKO1?SNJ?êG)mm?z7+P¥%khZ?
$M@=U=?????
%x3~=3?|39?>??yé??LzùS2_0ò?w(
?q)??bCì[x?q
?a?F|tL?íO??$@?*G?apBe??f′nz?;R7RBêü@+?UDW?/s)r?ú?x-o?üX>p?i?óüˉYe0o|?°p<|?.nA9?2"5??x??aüBo3?YU?é?]a?(?k?H4¨è0QfèêjV¨q ?QVNêF??7c?g!|L?5ˉ/¢?e0¥4?15A~á?Q?Yvá?@:2ü?÷F?A°r?y?)?$C?,?;?ù???'?,a?gX;3.`@??§!- ?F?fIà4 ?B?|£&jpe%àQ·b
#Nq???á??-(£?Pμp üˉàmìút??ˉà3??^Y%_4??ò??q1??-êBMson?Mte?T′?ósà+?]¨a[6T'??ê6MN¤D?abj_*?huóX???ùE¥(ò3??|4-2í"3ea?}?òé3q?§y?l¥ê?AU×y?2í}?B?′J?¥·ma£??3?7k2W06ìuBàùrTBT1d^C]y?* 33a§.o?t??úqKè??′ê';v@q3[*B,s?1±üym>?×V3?1i·ú17y??¢x???1ù??¤T9dz4?(&d¨d?z12!azd?Uòao?h÷w?¢?pá?srR?;{£>o.??eg(Y?fús:?_gúüoT$}G?kEDPo?U?D?3òíò8R°è
6cL?°4?oADKyP¥óèè9"?(gcüH?3?úˉèXúêè,f??L{?)t?é¤P£??μ
?è??aé'eq??è m4ZnübéóD`êuF·??JJ§í`??W nU?/QùtW?G6?&fBúmbj÷&°??(×òùGD|d?ja??K@?`.'T?$óR?Jí{ìE??è-I1??ˉab?+>[l??áT0?ê?)??O?[%??t1è.dx′ìDüXLe?{à -1í"??D;áDvú??`?
endstream
endobj
7 0 obj
<<
/Font 12 0 R
>>
endobj
[There was more lines]
As I am using
const { get } = useRequest (undefined, {
headers: { 'content-type':'multipart/form-data'},
responseType: "text" });
to download an csv and it works, I assume the problem is not with useRequest also. But here it is:
export const useRequest = <T>(
route: string = "",
options?: any[] | IncomingOptions | OverwriteGlobalOptions,
dependencies?: any[]
) =>
useFetch<T>(
`${process.env.NEXT_PUBLIC_API_URL}${route}`,
options,
dependencies
);
Does anyone have any other ideas on how I can solve this?
question from:
https://stackoverflow.com/questions/65937552/arraybuffer-request-on-typescript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…