开发者

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

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. Th开发者_开发问答e 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


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?
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜