#File downloading into FS doesnt work

62 messages ยท Page 1 of 1 (latest)

gusty zealot
#

Hey guys, Im trying to connect my app into my FS and after executing function, and recieving no errors, nothing happend. Any help?

I use this code

    public async createDataFile(contentData: any ,fileName: string){
        try {
            await writeFile(
                {
                    contents: contentData,
                    path: `${fileName}`,
                },
                {
                    dir: BaseDirectory.Download
                }
            );
        } catch (e) {
            console.log(e);
        }
    };
crisp viperBOT
#

Thank you for your message!

                1. Search the #1047150269156294677 forum for existing posts
                2. Search Github issues to see if this is a known issue
                3. Send the output of `tauri info`
                4. Provide reproduction steps for your issue
                5. Be polite and remember to follow the [Tauri Code of Conduct](https://github.com/tauri-apps/governance-and-guidance/blob/main/CODE_OF_CONDUCT.md)

                Once you've read this and taken the appropriate steps, react to this message
gusty zealot
#

I found the issue,
Tauri cannot save file that has some custom ext on the end

smoky breach
#

do you mean like filename.whatever-ext instead of well known stuff like .txt?

#

because that is supposed to work

gusty zealot
#

yes

smoky breach
#

what's your extension? My app writes .mwt files fine if you wanna try that

gusty zealot
#

gsp

#

its custom

gusty zealot
#

or not?

smoky breach
#

i don't understand the question, what do you mean with real extension?

gusty zealot
#

so, i believe that app I am working on , has own custom extention for files

#

so Tauri doesnt recognize it as existing one

#

because in reality it doesnt exist

smoky breach
smoky breach
#

i also tested a whatever.gsp file using your createDataFile code just now and it worked fine too

gusty zealot
#

so i dont know what can be problem... wghen i push .txt there, it works.. when i push .gsp there it doesnt

gusty zealot
#

MWT works for me too

#

but gsp doesnt

gusty zealot
#

@smoky breach sorry, One more question.. Is there any function, to create new file with different name like file(1).txt , than file(2).txt etc. without writing own function for it?

smoky breach
#

No

#

gotta do it yourself by checking if the file exists

gusty zealot
#

I have tried something, but I dont know how to check if last version of that file exists.. did you do it somewhere?

#

Now Only I can check is original 1st copy

smoky breach
#

but i'd imagine it would come down to a simple loop

gusty zealot
#

so I need to loop all files in directory, find the one, check which has the highest number and that will be the one?

#

How can I loop my files in Downloads ?

smoky breach
#

but yeah, either way works, yours has less fs operations but mine feels more natural to me

#

that's what you need for your variant

gusty zealot
#

thanks a lot, i go try it

fluid pendant
gusty zealot
#

any idea?

gusty zealot
#

@smoky breach sorry for disturbing you,

How to download PNG / Docx files into local system using tauri? Im trying to download blob of generated docx document but after it downloads, file is broken

smoky breach
#

hmm, that probably depends on how that file is generated. If you're talking about tauri writeBinaryFile function then all it does is take the bytes you give it and write them as-is. It's not aware of the actual file format so the binary must be formatted correctly, and idk how docx works but i think some file types need special file headers?

gusty zealot
#

hmmmm so all i need is to have binary data and pass them as content for file?

smoky breach
#

if that binary data is correctly formatted it should work for most stuff

#

again, idk how docx work, but pngs for example should work just fine

#

but they need more than just the pixel data, they also have some special headers upfront

gusty zealot
#

do you know about any good docs for pngs?

#

maybe I can find out something there

smoky breach
#

my knowledge is quite limited too though, i primarily looked into it to fix tauri's .icns icon generator which also uses png data: https://en.wikipedia.org/wiki/Apple_Icon_Image_format. There aren't many docs about it since it's an apple specific format so it made me look into the technicalities

gusty zealot
#

well thanks, I think I need to take more hourse to understand it properly ๐Ÿ˜„ looks pretty hard

smoky breach
#

i spent hours and hours on it and still don't understand it properly ๐Ÿ˜‚

#

buuut, since there are libraries that generate all the hard stuff a rough idea is often enough for the most part

gusty zealot
#

yeah, Okay thank you very much for your time dude. Wish me luck haha

gusty zealot
#

Of course I got this!!!

gusty zealot
#

@smoky breach imagine having AI that knows everything

#

xD ChatGPT just made it for me

#
  Packer.toBlob(doc).then(blob => {
            console.log(blob);
            const fileReader = new FileReader();
            fileReader.onload = async () => {
                const arrayBuffer = fileReader.result as ArrayBuffer;
                const uint8Array = new Uint8Array(arrayBuffer);
                this.tauriFsService.createBinaryFile(uint8Array, focusedGoalName, '.docx');
            };
            fileReader.readAsArrayBuffer(blob);
        });
#

This is how to get binaryData from blob for docx

#

i believe same strategy will be for ONG