Is it possible to write data to a local file?

#1

For example, I have a string which is a base64 encoded string that represents an image.

Is it possible to write that string to a file using C3 platform? Similar to functionality of fs.writeFile or fs.writeFileSync in NodeJS.

Below is an example in NodeJS, which is what I’d like to do in C3 platform.

        let screenshot = new Buffer(res.value, 'base64')

        if (typeof filename === 'string') {
            fs.writeFileSync(filename, screenshot)
        }
0 Likes

#2

Yes there is a type LocalFileSystem which can be used for this. (see FileSystem and its mixins)

Note that “local” in this case means “the server where the code is running” and may be a worker node.
If a subsequent function is running on a DIFFERENT worker node and tries to access the same file it might not be found.

0 Likes

#3

For a file system which is consistent accross workers, see the type S3 (mixes FileSystem)

0 Likes