Skip to content Skip to sidebar Skip to footer

Decode File To Stream, From Base64 Encoded String. How To Do That?

I have a string, recived by my app from web-browser. String contains PNG image, and encoded to base64. It isn't my stupid idea, convert image to base64 string )) That doing web-br

Solution 1:

I solved my problem by other way. In JS I send data via headers(Ajax.setRequestHeader), and the file I send in the POST stream. After that DecodeStream, from EncdDecd is working correctly, I got the image from string.

        Id := ARequestInfo.RawHeaders.Values['OwnerId'];
        sName := ARequestInfo.RawHeaders.Values['Name'];
        sDesc := ARequestInfo.RawHeaders.Values['Desc'];
        sURL := ARequestInfo.RawHeaders.Values['URL'];
...
          if (ARequestInfo.PostStream <> nil) then //We have the image!
          begin
            MS := TMemoryStream.Create;
            MS2 := TMemoryStream.Create;
            try
              MS2.LoadFromStream(ARequestInfo.PostStream);
              DecodeStream(MS2, MS);
              MS.SaveToFile(myDir + '1.png');
            finally
              FreeAndNil(MS);
              FreeAndNil(MS2);
            end;
          end;

Also you can try mixed of alternative multipart/form-data encoding. But Indy doesn't have implemented classes for parsing recived data in this format.

Post a Comment for "Decode File To Stream, From Base64 Encoded String. How To Do That?"