C#如何写从request.binaryread一个JPG图片 [英] c# how to write a jpg image from request.binaryread

查看:730
本文介绍了C#如何写从request.binaryread一个JPG图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Flash应用程序,它发送原始数据的JPG图像到一个特定的URL Send.aspx。在Send.aspx我使用request.binaryread()得到的总长度的要求,然后在数据读取的字节数组。
然后,我写的数据为JPG文件到服务器。在code为如下:

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();

时,得到生成的文件,但没有图像中的它。它总是显示在任意图形浏览器为空。我错过了什么角色。我应该写它以文件之前先用JPG格式编码?在此先感谢

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...

是否有可能客户端没有正确提供数据?也许是它提供为base64-CN codeD数据?

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.)

我建议你在你最终拯救VS原始文件仔细一看:

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


  • 他们是相同的长度?如果不是,这是长?

  • 如果它们是相同的长度,做他们的MD5校验和匹配?

  • 如果您有一个二进制文件编辑器中同时查看,他们是否都一致?任何明显的差异?

这篇关于C#如何写从request.binaryread一个JPG图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆