Exemplo n.º 1
0
        public async Task <string> CompressDataUriAsync(string dataUri)
        {
            string mimeType  = FileHelpers.GetMimeTypeFromBase64(dataUri);
            string extension = FileHelpers.GetExtension(mimeType);

            if (!IsFileSupported("file." + extension))
            {
                return(dataUri);
            }

            string temp        = Path.Combine(Path.GetTempPath(), _dataUriPrefix + Guid.NewGuid() + "." + extension);
            bool   isFileSaved = FileHelpers.SaveDataUriToFile(dataUri, temp);

            if (isFileSaved)
            {
                await CompressFilesAsync(temp);

                string base64 = FileHelpers.ConvertToBase64(temp);
                File.Delete(temp);

                return(base64);
            }

            return(dataUri);
        }