Save File
Save File
SDK function: saveBase64Data
saveBase64Data This function saves Base64 data encoded as a string to the user's device with the specified file name and MIME type. You can save data in various formats such as images, text, and PDFs.
Signature
function saveBase64Data(params: SaveBase64DataParams): Promise<void>;Parameters
params · Required ·
SaveBase64DataParamsAn object containing the data to save and file information.
params.data · Required ·
stringA Base64-encoded data string.
params.fileName · Required ·
stringThe name of the file to save. You must include the extension too. For example, you can save it as 'example.png'.
params.mimeType · Required ·
stringThe MIME type of the file to save. For example, specifying 'image/png' means an image, and 'application/pdf' means a PDF file. For more details, see MIME documentation.
Example
Saving Base64 image data to the user's device
import { saveBase64Data } from '@apps-in-toss/web-framework';
async function handleSaveBase64Data() {
try {
await saveBase64Data({
data: 'iVBORw0KGgo...',
fileName: 'some-photo.png',
mimeType: 'image/png',
});
console.log('Data saved successfully');
} catch (error) {
console.error('Failed to save data:', error);
}
}import { saveBase64Data } from '@apps-in-toss/web-framework';
import { Button } from '@toss/tds-mobile';
function SaveButton() {
const handleSave = async () => {
try {
await saveBase64Data({
data: 'iVBORw0KGgo...',
fileName: 'some-photo.png',
mimeType: 'image/png',
});
} catch (error) {
console.error('Failed to save data:', error);
}
};
return <Button onClick={handleSave}>Save</Button>;
}Last updated
Was this helpful?