开发者

Base64 Encode - Decode Python and ASP.Net?

开发者 https://www.devze.com 2023-03-30 09:19 出处:网络
i m trying encode data on python with \"base64.encodestring()\" then i send encodedData to my asp.net service and trying decode this data.But this data is invalid.

i m trying encode data on python with "base64.encodestring()" then i send encodedData to my asp.net service and trying decode this data.But this data is invalid.

Python function code () :

randomString=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(10))
fileNameString=randomString+"_"+request.vars['file'].filename
pathToFile开发者_如何学Go="/tmp/"+fileNameString
f = open(pathToFile,"wb")
f.write(request.vars["file"].file.read())
f.close()

f = open(pathToFile,"rb")
data=f.read()
f.close()
encodedData=base64.encodestring(data)

return encodedData

C# Code:

byte[] filebytes = Convert.FromBase64String(encodedData);
FileStream fs = new FileStream(crmPath + fileName,
FileMode.CreateNew,
FileAccess.Write,
FileShare.None);
fs.Write(filebytes, 0, filebytes.Length);
fs.Close();

this codes works towards save file but when i try to open this file it isnt opened

0

精彩评论

暂无评论...
验证码 换一张
取 消