c# how to write a jpg image from request.binaryread

泄露秘密 提交于 2019-12-24 10:55:35

问题


I have a flash app which sends raw data for a jpg image to a particular url Send.aspx . In Send.aspx I am using request.binaryread() to get the total request length and then read in the data to a byte array. Then I am writing the data as jpg file to the server. The code is given below:

FileStream f = File.Create(Server.MapPath("~") + "/plugins/handwrite/uploads/" + filename);
            byte[] data = Request.BinaryRead(Request.TotalBytes);

            f.Write(data, 0, data.Length);

            f.Close();

The file is getting created but there is no image in it. It always shows up as empty in any graphic viewer. What part am I missing. Am I supposed to use jpg encoding first before writing it to file? Thanks in advance


回答1:


Well, you should use a using statement for your file stream, but other than that it looks okay to me.

A few suggestions for how to proceed...

Is it possible that the client isn't providing the data properly? Perhaps it's providing it as base64-encoded data?

Have you already read some data from the request body? (That could mess things up.)

I suggest you look closely at what you end up saving vs the original file:

  • Are they the same length? If not, which is longer?
  • If they're the same length, do their MD5 sums match?
  • If you look at both within a binary file editor, do they match at all? Any obvious differences?


来源:https://stackoverflow.com/questions/6715737/c-sharp-how-to-write-a-jpg-image-from-request-binaryread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!