Writing Mp4 File From Request.InputStream?

May 28, 2010

I have a page posting data to me via HTTP POST. What i want is write posted data into mp4 video format file. Here my code how to write that file:

string strFilePath = "D:\Video.mp4";
using (FileStream fs = new FileStream(strFilePath, FileMode.Create))
byte[] bytes = new byte[Request.InputStream.Length];
Request.InputStream.Read(bytes, 0, (int)Request.InputStream.Length);
fs.Write(bytes, 0, bytes.Length);

My problem is that i got the file, but it's corrupt when playback. Is there any problem with my stream or i missing some decode for mp4 file?

View 2 Replies

Similar Messages:

First Request Fails With HTTP 400 (Bad Request) After Reading HttpRequest.InputStream

Oct 24, 2010

I develop an asmx web service (i.e. ASP.NET 2.0). There's a piece of code that may read the contents of the HTTP request (via HttpContext.Current.Request.InputStream) while processing it. I realise that InputStream may only be read once for a request, and I make sure I never try to read it more than once.

The problem seems to be that if InputStream happens to be read during the early stages of the application's lifecycle (e.g. after pskill w3wp, during Application_Start), the HTTP request fails with a HTTP 400 - Bad Request error, with no explanation given, no exception thrown and no entry in the httperr log. If it is read later (e.g. within the web method itself), requests run fine whether InputStream is read or not. Application_Start runs fine if InputStream isn't read.

Is this some sort of ASP.NET bug? IIS bug? Or am I doing something wrong by daring to read InputStream? And if so, is there another way to get a look at the "raw" contents of the request without disturbing the inner workings of IIS/ASP.NET? In short, adding this code within Application_Start is enough to reproduce this error: using (StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream))reader.ReadToEnd();

View 1 Replies

Valum File Upload - Works In Chrome But Not IE - Image Img = Image.FromStream(Request.InputStream)

Dec 6, 2010

I'm using a slightly modified version of Valum's upload [github link], I've modified it to upload to a database but haven't modified the javascript that it is using to get the file into the Request as an InputStream. The following line of code is failing in IE 8 but is confirmed to work in Chrome. using (Image imgInput = Image.FromStream(Request.InputStream)) The error received is "Parameter not valid". It appears to be having an issue with the Input Stream being used but it exists/has data (not sure how to validate if the data is good or not).

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="file-uploader">
<p>Please enable JavaScript to use file uploader.</p>
<script src="/Scripts/fileuploader.js" type="text/javascript"></script>
<script type="text/javascript">
function createUploader() {
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader'),
action: '/Admin/FileUpload/' + <%= Model.PropertyId %>,
debug: true
window.onload = createUploader;
public JsonResult FileUpload(int id)
byte[] newImageByteArray = GetByteArrayForResizedImage(350, Request.InputStream);
byte[] thumbnailByteArray = GetByteArrayForResizedImage(150, Request.InputStream);
//Add to DB
catch (Exception ex)
// This is where the exception is caught
return Json(new { success = false, message = ex.Message }, "application/json");
return Json(new { success = true }, "application/json");
private static byte[] GetByteArrayForResizedImage(int imageSize, Stream inputStream)
byte[] imageByteArray;
// For some reason in IE the inputStream here is causing it to crash
using (Image imgInput = Image.FromStream(inputStream))
//Image processing
return imageByteArray;
fileuploader.js - qq.FileUploader
* Class that creates upload widget with drag-and-drop and file list
* @inherits qq.FileUploaderBasic
qq.FileUploader = function(o){
// call parent constructor
qq.FileUploaderBasic.apply(this, arguments);
// additional options
qq.extend(this._options, {
element: null,
// if set, will be used instead of qq-upload-list in template
listElement: null,
template: '<div class="qq-uploader">' +
'<div class="qq-upload-drop-area"><span>Drop files here to upload</span></div>' +
'<div class="qq-upload-button">Upload a file</div>' +
'<ul class="qq-upload-list"></ul>' +
// template for one item in file list
fileTemplate: '<li>' +
'<span class="qq-upload-file"></span>' +
'<span class="qq-upload-spinner"></span>' +
'<span class="qq-upload-size"></span>' +
'<a class="qq-upload-cancel" href="#">Cancel</a>' +
'<span class="qq-upload-failed-text">Failed</span>' +
classes: {
// used to get elements from templates
button: 'qq-upload-button',
drop: 'qq-upload-drop-area',
dropActive: 'qq-upload-drop-area-active',
list: 'qq-upload-list',
file: 'qq-upload-file',
spinner: 'qq-upload-spinner',
size: 'qq-upload-size',
cancel: 'qq-upload-cancel',
// added to list item when upload completes
// used in css to hide progress spinner
success: 'qq-upload-success',
fail: 'qq-upload-fail'
// overwrite options with user supplied
qq.extend(this._options, o);
this._element = this._options.element;
this._element.innerHTML = this._options.template;
this._listElement = this._options.listElement || this._find(this._element, 'list');
this._classes = this._options.classes;
this._button = this._createUploadButton(this._find(this._element, 'button'));
fileuploader.js - qq.FileUploaderBasic
* Creates upload button, validates upload, but doesn't create file list or dd.
qq.FileUploaderBasic = function(o){
this._options = {
// set to true to see the server response
debug: false,
action: '/server/upload',
params: {},
button: null,
multiple: true,
maxConnections: 3,
// validation
allowedExtensions: [],
sizeLimit: 0,
minSizeLimit: 0,
// events
// return false to cancel submit
onSubmit: function(id, fileName){},
onProgress: function(id, fileName, loaded, total){},
onComplete: function(id, fileName, responseJSON){},
onCancel: function(id, fileName){},
// messages
messages: {
typeError: "{file} has invalid extension. Only {extensions} are allowed.",
sizeError: "{file} is too large, maximum file size is {sizeLimit}.",
minSizeError: "{file} is too small, minimum file size is {minSizeLimit}.",
emptyError: "{file} is empty, please select files again without it.",
onLeave: "The files are being uploaded, if you leave now the upload will be cancelled."
showMessage: function(message){
qq.extend(this._options, o);
// number of files being uploaded
this._filesInProgress = 0;
this._handler = this._createUploadHandler();
if (this._options.button){
this._button = this._createUploadButton(this._options.button);

View 1 Replies

C# - Change HttpContext.Request.InputStream

Apr 19, 2010

I am getting lot of errors for HttpRequestValidationException in my event log.

Is it possible to HTMLEncode all the inputs from override of ProcessRequest on web page. I have tried this but it gives context.Request.InputStream.CanWrite == false always.

Is there any way to HTMLEncode all the feilds when request is made?

public override void ProcessRequest(HttpContext context)
if (context.Request.InputStream.CanRead)
IEnumerator en = HttpContext.Current.Request.Form.GetEnumerator();
while (en.MoveNext())
//Response.Write(Server.HtmlEncode(en.Current + " = " +
long nLen = context.Request.InputStream.Length;
if (nLen > 0)
string strInputStream = string.Empty;
context.Request.InputStream.Position = 0;
byte[] bytes = new byte[nLen];
context.Request.InputStream.Read(bytes, 0, Convert.ToInt32(nLen));
strInputStream = Encoding.Default.GetString(bytes);
if (!string.IsNullOrEmpty(strInputStream))
List<string> stream = strInputStream.Split('&').ToList<string>();
Dictionary<int, string> data = new Dictionary<int, string>();
if (stream != null && stream.Count > 0)
int index = 0;
foreach (string str in stream)
if (str.Length > 3 && str.Substring(0, 3) == "txt")
string textBoxData = str;
string temp = Server.HtmlEncode(str);
//stream[index] = temp;
data.Add(index, temp);
if (data.Count > 0)
List<string> streamNew = stream;
foreach (KeyValuePair<int, string> kvp in data)
streamNew[kvp.Key] = kvp.Value;
string newStream = string.Join("", streamNew.ToArray());
byte[] bytesNew = Encoding.Default.GetBytes(newStream);
if (context.Request.InputStream.CanWrite)
context.Request.InputStream.Position = 0;
context.Request.InputStream.Write(bytesNew, 0, bytesNew.Length);

View 1 Replies

C# - Leaving A BinaryReader Object Un-disposed In Order To Keep Request.InputStream Alive?

Feb 1, 2011

I have a couple methods to handle the saving of an image using Request.InputStream. I have two extensions that share the HttpContext. In one of my methods, I'm using a BinaryReader to read in the contents and do the processing. However, naturally, when disposing the BinaryReader, it closes off the InputStream property on Request. My SECOND method uses the same input stream to create a thumbnail.

Bascially, I need a way to keep the Request.InputStream property alive after disposing the reader in the first method. Is this possible? Here are my two methods. SaveImageStream() is called first, then GenerateThumbnail().


View 2 Replies

How To Read Inputstream From HTML File Type In C# Without Using Server Side Control

Sep 17, 2010

I have the following form

<form id="upload" method="post" EncType="Multipart/Form-Data" action="reciver.aspx">
<input type="file" id="upload" name="upload" /><br/>
<input type="submit" id="save" class="button" value="Save" />

When I look at the file collection it is empty.

HttpFileCollection Files = HttpContext.Current.Request.Files;

How do I read the uploaded file content without using ASP.NET server side control?

View 2 Replies

Web Forms :: Deleting List Item / File - Writing New File With Remaining Items

Dec 23, 2010

Spent ages trying to get this right but am struggling now. I have a list box and textbox, I can happily enter Email addresses into the textbox which are saved into a text file and populated in a list box. I want to be able to select a list item and delete it, along with it's record in my text file. I was going to do it by on the delete list item / button click, it delete's the text file and then writes and a new one with the remaining list items in the list box. Unfortunately it's re-writing the file but either not including the remaining list items. Here's some examples of what I've changed and what populates the text file:

StreamWriter1.WriteLine(Addresses.Items); - System.Web.UI.WebControls.ListItemCollection
StreamWriter1.WriteLine(Addresses.Text); - A blank line?!?

The code is below. The reason I wouldn't allow the user to delete the first list item is because I thought the code was working ok but for some reason putting in a blank line to start with, and if I deleted the line it'd delete all file content. No, I don't know why I thought that either.


where I've gone wrong? I've not actually slept since I woke up at 8am yesterday. It's now 11am... today.

View 5 Replies

Writing To A File At Runtime

May 17, 2010

I am trying to write some lines at runtime to a text file using streamwriter, but i have to allow only 100 lines to be written to that file, if 101 line is supposed to be written to that file than first line of the file must get discarded/deleted and file must allow writing the 101 line so the file will actually always contain only 100 lines.

View 10 Replies

Writing Xml To Memory Instead Of A File?

Feb 18, 2010

Is there a way to write xml directly to an object that can represent it in memory and use that with XPath instead of an .xml file?

View 1 Replies

Web Forms :: Writing To Log File On First Pageload?

Oct 27, 2010

Based on this piece of code, I want to do exactly like this demonstration. However, correct me if I'm wrong but if two or more users somehow simultaneously access the web page at the same precise nanosecond in time, then wouldn't we have a race condition? So is this piece of code valid? How would I correct this to make it thread safe?


View 3 Replies

Use Of Writing Method As Webmethod In Cs File?

Dec 1, 2010

1.What is the use of writing method as webmethod in cs file

2.what is the use of calling webmethods through javascript file.

View 4 Replies

Writing To A File Which Can Be Password Protected?

Mar 10, 2011

i have table data which i am currently writing to an excel file, but i need to be able to securely password protect the file. Ive been told excel passwords are easy to break, so is there another file type which i can dynamically write to and password protect for emailing elsewhere (and requiring receiver to type password in to access it)?

View 2 Replies

Web Forms :: Rollback From File Reading / Writing

Mar 9, 2011

I am using more than one files to read and write to the server. Suppose during writing or reading any of files gets error the already stored files need to be rollback or removed from storing.So that the user agin try to write without error. Simply the all of the files need to be stored into the server without error, of error occurs to any of file none of files need to be read/write

View 2 Replies

Writing .txt File When There Is Large Amount Of Data?

Jul 22, 2010

i have write data from db to .txt file,where db have large amount data,i need to wite data into file, if some error occure, then reInitiated that file and write data again without stop process.that is Continuous calling same process

View 2 Replies

Web Forms :: Writing A File (doc) To Different Server On The Network?

May 18, 2010

I am trying to create and write a file on a remote server using the below code:


but i am running into issues and getting errors. Below are some tries i have given. My IIS settings are 'Anonymous Access' checked and also 'Integrated windows authentication' checked.

a. As i understand asp.net site would run using ASPNET account, i tried giving full permission to ASPNET account to the folder on the remote server (where i want to drop the file). But i am getting this error - "Logon failure: unknown user name or bad password"

b. The other thing i tried is giving full permissions to 'Everyone' to the remote server folder. But i get the same error as above. But when in my web.config i enable impersonation by using:

then the error goes away and everything works fine as expected. The file gets dropped to the network share.

why the scenario (a) doesn't work because that should work as if i give ASPNET account full access to the folder, and my website is running under the same account, then it should work.

Also, in the scenario (b), i believe it is using my domain account, as the impersonation is true without specifying any username and password and also the remote server folder has Everyone access to full control.
BUT, as a security breach, i cannot use Everyone account to the remote folder. In that case, how can i make this working.

I was also thinking if i can use the virtual directory as the path to the remote folder, something like
http://domain.com/remotefolder but dont know how can i use this approach. Can someone pls share some sample code and the configuration.

View 1 Replies

Web Forms :: Writing Bitmap File On Server?

Oct 19, 2010

I'm making an application which takes image from user upload it to server and then perform any image processing like to convert to gray or invert etc.

My problem is this when i did the process on image to gray it or invert then how to write this new file on server or is there any other way so that i would be able to show this (new) image to user and make it downloadable?

View 2 Replies

Web Forms :: File Reading And Writing For Number Of User

Mar 16, 2011

In my application i want to share one .txt for read and write among no. of users. in Button click i m writing data in that file and in tick event of Timer i m reading that file, In tick event i m reading that file based on file based cachin means if file have been changed then only i m reading that file but when i have put m application i IIS then i m not able to get updated file.

View 2 Replies

Configuration :: Writing A Connection String In Web.config File?

Jul 30, 2010

I have written the web.config for same server without username and server and its working.

but not been able to provide the username and password in web.config file.

Following is my web.config for Server:


I have to write another web.config for client application with username and passoword. how could i use it.

server name is "BM", User is "Sa" and Password is "abc"

View 11 Replies

C# - Complete The Post Back After Writing Out A File To The Response?

Jan 28, 2011

I have a button that when clicked, will generate a PDF and write it out to the response.This is the basic structure of the code:

using(Stream stream = generatePdf())


Downloading the file works fine, except that it doesn't complete the postback.If I were to throw an exception above file.Transmit, the error handling would work properly and I would see the message get displayed in my browser. However, if there is an exception after the file.Transmit then nothing happens. The user saves/opens the pdf and the page does not reload.How can I make it so that the postback always completes, that way I can display an appropriate message to the user?

View 2 Replies

Web Forms :: Writing A Log In Xml File Or Insert Query In Database?

Feb 20, 2010

i want to maintain a log of the visitors for a website.. the number of visitors is fix approximate (800), but i have to maintain the record of each visit page wise like page Id, time visited, user id. i am doing it using a database as it was .

i was asked to use a insert query on every page ,(ie each time user visits a page write the log to database), but i dint like the idea.. of making server trips every time the user visits a page and also we have a seperate database server. I had a idea of using XML.. but which is the best way performance wise writing a log in Xml file or insert query in database?

View 4 Replies

Web Forms :: Writing To A Text File Upon Application Login

Aug 24, 2010

I have the following subroutine in an asp.net application class. The subroutine writes data to a text file upon application login. My question is that if this function was called at the same time by two different users would it cause any kind of error. Is there a need for a try catch?

Public Shared Sub writeToLogFile(ByVal UserName As String)
Dim strLogMessage As String = String.Empty
Dim strLogFile As String = System.Web.HttpContext.Current.Server.MapPath("~/Log.txt") Dim swLog As StreamWriter
strLogMessage = DateTime.Now.ToShortDateString().ToString() " ==> " & UserName
If Not File.Exists(strLogFile) Then
swLog = New StreamWriter(strLogFile)
swLog = File.AppendText(strLogFile)
End If
End Sub

View 5 Replies

C# - StreamWriter Stops Writing When File Is Opened From Web Link?

Mar 22, 2010

Following on from my previous question...

The following code creates log files on a web server:

private void LogMessage(Message msg)
using (StreamWriter sw = File.AppendText(_logDirectory + DateTime.Now.ToString("yyyyMMddHH") + ".txt"))

The log files are linked to from an admin page on the web site:

foreach (FileInfo file in logDir.GetFiles())
Response.Write("<a href='http:// .... /Logs/" + file.Name + "'>" + file.Name + "</a>");

I'm getting the problem that after someone looks at one of the log files from the link, that log file stops being written to.

View 1 Replies

.net - Log4net - FileAppender Writing New Entries At The Beginning Of File?

Jan 11, 2010

Is is possible to configure FileAppender in log4net to add new entries at the beginning of log file? Currently it is adding entries at the end and reading newest entries requires scrolling whole log down. It would be more comfortable to read from the beginning.

View 2 Replies

Web Forms :: Writing Metadata To File Error On Build?

Jun 29, 2010

I keep getting this error when trying to Run or Build my ASP Project. A few details:

I migrated this project from VS 2003 to VS 2008 (C#) It works fine when I successfully compiled it and deployed onto server.I have Plenty of free diskspace available.I have 4 GB Ram and Windows XP So each time I try to build this project, I get the following error.

Error 57
Unexpected error writing metadata to file 'C:InetpubwwwrootProject.IntranetobjTestProject.Intranet.dll' -- 'Not enough storage is available to complete this operation. 'Project.Intranet

View 1 Replies

Writing Encrypted Connection String To Web Config File?

Jun 28, 2011

How to programmatically write an encrypted connectionString to a Web.Config file?

View 5 Replies

Copyrights 2005-15 www.BigResource.com, All rights reserved