Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 3 Next »



Convert base64 encoded string to blob


In some cases file data might be represented by base64 encoded strings. The following can be used to convert from base64 encoded file data strings to blob:

persistent object CropQualityPicture {
	blob image;
	string imageStr;
}
// Convert base64 string to blob
cropQualityPicture.image = Blob:fromString(cropQualityPicture.imageStr);

Note that if the resulting blob is to be used with any frontend widgets, it is recommended that the Blob:wrapFromString built in function is used instead since this will also populate meta fields for the blob that are needed by most frontend widgets that handle blobs.




Convert blob to base64 encoded string

Similarly to the above, blobs can also be converted to base64 encoded strings:

// Convert blob to base64 string
cropQualityPicture.imageStr = Blob:toString(cropQualityPicture.image);




Convert base64 encoded string to a wrapped blob

Since blob fields on objects are automatically accompanied by meta attributes that describe mime type, file size and file name, an additional conversion is available where a base64 encoded string can be converted to a built-in object that wraps the blob and includes the above mentioned meta fields:

MezBlobResult blobWrapper = Blob:wrapFromString(cropQualityPicture.imageStr, "image/jpeg", "file_name_str");

// This assignment will assign the blob field and also copy the meta fields
cropQualityPicture.image = blobWrapper.blobData;
// Built-in wrapper object
object MezBlobResult {
	blob blobData;

	// blobData_mtype__, blobData_fname__, blobData_size__, are included by default
}




Download a file for a blob

Blobs can also be downloaded as files on the frontend. One method is to use the file browser widget. Another more flexible method is with the Mez:downloadFile built-in function.






  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.