c# - System.Convert.ToBase64String returning different result than the input to System.Convert.FromBase64String -
i'm writing web application saves images web database. currently, use save images follows:
[webmethod] public static void save(string pictures) { // pictures object containing url of image along metadata list<imageobject> imagelist = new javascriptserializer().deserialize<list<imageobject>>(pictures); (int = 0; < imagelist.count; i++) { var webclient = new webclient(); byte[] bytearray = webclient.downloaddata(imagelist[i].url); imagelist[i].picture = bytearray; } // sql save imagelist } imageobject:
[datacontract] public class imageobject { [datamember] public string url { get; set; } [datamember] public string picture { get; set; } } now, works fine downloading url. entry saved database:
0xffd8ffe000104a464946000101[...]331b7cca7f0ad3a02dc8898f to display image, callsystem.convert.tobase64string()after retrieving , use imagesrc. however, trying add functionality users upload own pictures. function this, called an<input />:
function uploadpicture(){ var numpics = document.getelementbyid("uploadedpictures").files.length; var ofreader = new filereader(); ofreader.onload = function (ofrevent) { var src = ofrevent.target.result; document.getelementbyid('image').src = src; } ofreader.readasdataurl(document.getelementbyid("uploadedpictures").files.length; } when using this, image source browser (over 2 mb when original ~500 kb):
data:image/bmp;base64,/9j/4aaqskzjrgabageay[...]k8ttmzebcsebseryem493ihafihwq6vklov/z this gets displayed when used source. however, since not actual url (andwebclient.downloaddata()is restricted urls of < 260 characters), have been trying other methods save data database. however, cannot seem find function save in same format aswebclient.downloaddata(). example, have looked @ converting base 64 string image , saving it, of answers seem useconvert.frombase64string(), using appears save in different format database:
0x64006100740061003a0069006d0[...]10051004500420041005100450042004 trying usesystem.convert.tobase64string()on returns
zabhahqayqa6agkabqbhagcazqavagiabqbwadsaygbh[...]uwblafiawqblag0anaa5admasqbiaeeazgbpaegavwbxadyadgblagwatwb2ac8awga= which different usedconvert.frombase64string()on. other things found on google try , save in same format or display image have not worked far.
hence, wondering whether there exists method convert result afilereaderto same format aswebclient.downloaddata()does urls or if there way convert the0x6400[...]data format can displayed using an<img>source.
it turns out reason data saved database began with0x64006100[....]instead of0xffd8ffe0[...]was due me forgetting strip uri of initialdata:image;base64,. after doing this, saves , read usingsystem.convert.tobase64string().
Comments
Post a Comment