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

Page
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Upload-Pictures</h2>
<div id="file-uploader">
<noscript>
<p>Please enable JavaScript to use file uploader.</p>
</noscript>
</div>
<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;
</script>
</asp:Content>
Controller
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult FileUpload(int id)
{
try
{
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>' +
'</div>',
// 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>' +
'</li>',
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'));
this._bindCancelEvent();
this._setupDragDrop();
};
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){
alert(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);
}
this._preventLeaveInProgress();
};

View 1 Replies


Similar Messages:

C# - ASHX Image Handler Works With Chrome Not IE8?

Jul 25, 2010

I've created code to retrieve an image from the file system using an ASHX handler. The code displays the image correctly in Chrome, but I get a broken image in IE:

[Code]....

View 2 Replies

MVC :: Image Upload Failing In Google Chrome

Feb 10, 2010

I have an image upload form:

[Code]....

That posts back to the action
[Code]....

The code works accross all browsers but Google Chrome. My IDE is Visual Studio 2k8, and I haven't figured out how to debug on Google Chrome with it, however, I am throwing error messages, and I know that for some reason under chrome, the following check doesn't pass:
[Code]....

So apparently, under Chrome, the HttpPostedFileBase parameter picture isn't encoded right and loses its mime type, howwever, this might not be the only problem. What is excatly wrong with the HttpPostedFileBase parameter under Chrome, and how can I fix it?

View 3 Replies

Data Controls :: How To Upload Default Image Into Database When No Image File Selected

May 9, 2013

I have to insert default image into databse..when no image is selected from fileupload control.. Here is code...not working for default image...

if (FileUpload1.HasFile){string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("~/UPLOADEDFILES/" + FileName));
feedBack.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileName));
} else {
string filename="~/images/"+ "sun.gif";filename.pPropertyImage = filename;FileUpload1.SaveAs(MapPath(filename));}

View 1 Replies

Web Forms :: Check Image File Size And Dimensions (Height And Width) Before Image Upload

Oct 18, 2013

How to upload images with some conditions

Like

size not gretr than 50 kb

with = 110px, height 140 px

etc..

View 1 Replies

Web Forms :: Upload Image From Desktop To Server Works 1 Of 10 Times?

Jul 6, 2010

I have a problem with upload a picture from desktop to a folder on server. The problem is that it seems to work about 1 of 10 times wich confuses me. Perheps something with this code is not enterily correct ?

First I check for if Pic1.jpg or Pic1.gif exists and then delete it if it exist. Then I want the uploaded picture to be named the same. Pic1.jpg if it is .jpg format or Pic1.gif if the uploaded picture has a .gif format.

[Code]....

View 35 Replies

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

Configuration :: Upload Image - Request Failed - Getting Error

Oct 5, 2010

Having following error when i upload the image

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

View 1 Replies

C# - "Parameter Is Not Valid" Exception From System.Drawing.Image.FromStream() Method?

Aug 27, 2010

I got a hard time with the Image.FromStream method in my website. The code below works perfect on my computer. But when I uploaded it to the test server, it always gives me "Parameter not valid" exception.

if (!afuImageFile.IsUploading && afuImageFile.HasFile)
{
System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent);
}

the afuImageFile is an AsynFileUploader control in Ajax Tool Kits. afuImageFile.FileContent is a HttpInputStream.

View 1 Replies

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

Web Forms :: Display Image In Image Control After Upload On Server Then Save To Database

Apr 16, 2013

I have filed image type varbinary

I want upload image and show then with click button save

store in db

View 1 Replies

Image Upload Control (bonus - Allows Users To Crop Image Before Saving)

Apr 10, 2010

We have a scenario where we would like to allow our users to upload images to the site. We are running on ASP.Net. A quick search did not result in anything good. It would be great if the control is free/open source but we do not mind paying a little bit.

View 1 Replies

Accessing Image File Of Client's Machine (without Using File Upload Control)

Apr 14, 2010

I want to access one image file residing in C: of the client's machine. I know with the help of file upload control (or say input type=file), this would be easy. Due to nature of my application (Its a KIOSK application), user is not expected to select file. I am just wondering how should I implement reading file without using file upload control. I want to store this file in Images folder of server. I am beginner to WCF. Should I look towards WCF?

View 7 Replies

Web Forms :: How To Upload An Image In A Webpage And Display It In An Image Control

Jan 22, 2011

i'm a new in web page application

can any one tll me how to upload in image in the web page and dispay it in an image control then save the path to the database?

View 2 Replies

Web Forms :: How To Upload New Image Replacing Old Image In Local Folder

Feb 2, 2011

I'm having an image in my page displayed to clients form a folder under same apllication folder,I also have a form in the same page that accepts an image file to be uploaded. The image that is uploaded via this form should take the place of the image that's displayed in the page with the name newly givven at runtime. The new image should be uploaded in the same directory with the new name provided, which means it overwrites the previous image.

View 5 Replies

AJAX :: Upload Image Using FileUpload And Display In Image Control?

Jan 15, 2014

I want to upload image through fileupload toolbox and display it in image control.

The image control should get the path from fileupload and should display the image.

I have done it with following code attached

HTML Markup-

<asp:FileUpload ID="FileUpload1" runat="server"
style="top: 256px; left: 533px; position: absolute; height: 23px; width: 217px" ForeColor="White" />
<asp:Button ID="btnset" runat="server" Font-Bold="False" Font-Names="Times New Roman" Font-Size="Medium" style="top: 309px; left: 605px; position: absolute; height: 26px; width: 81px" Text="Set Photo " />
<asp:Image ID="Image2" runat="server" style="top: 66px; left: 568px; position: absolute; height: 152px; width: 136px" BorderColor="#CCCCFF" BorderStyle="Ridge" />

VB Code-

Protected Sub btnset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnset.Click
Image2.ImageUrl = FileUpload1.FileName
End Sub

View 1 Replies

Image Upload To File System?

Dec 28, 2010

I have this file upload control. I have created a folder name "images" in my visual studio project. I want to upload image into this folder. BUT, when I am uploading a image, system does not show any error. It is uploading the image. But I cannot see it into the "images" folder. But, when I browse the folder from my computer like if I go to c:/my documents/vs project/my project/images. i can see the uploaded image. Then why the image is not visible from my visual studio?? as the image is not visible in my visual studio project, user can not see the uploaded image. my code is as below:

[Code]....
[Code]....

View 7 Replies

Upload An Image To The File Systm?

Mar 29, 2011

how can i upload an image to the file systm?

View 2 Replies

Web Forms :: How To Upload Image In Image Control When You Browse

May 9, 2010

iam using asp.net with c#

i want to display image in a image control as soon as we browse with file upload control ,i dont want to use button click event

[Code]....

View 1 Replies

C# - Restrict A User To Upload Only Image File

May 28, 2010

I am using FileUpload control to facilitate Image file upload on my website. I want to restrict a user to upload only Image file. I am using

if (fupFirmLogo.PostedFile.ContentType == "image/Jpeg")
{
}

to check if the file is a image or not. I want to allow all image extensions like PNG, GiF, Jpeg, tif , BMP etc. How should I do it.

View 4 Replies

Get Image Dimensions Using Javascript During File Upload?

May 19, 2010

I have file upload UI element in which the user will upload images. Here I have to validate the height and width of the image in client side. Is it possible to find the size of the image having only the file path in JS?Note: If No, is there any other way to find the dimensions in Client side?

View 4 Replies

How To Upload A File On The Click Of An Image Button

Mar 30, 2011

I have an 'Attach image button' in my web page, I don't want see the the file upload control cannot use any third party tools in my page. On the click of the 'Attach image button' it will directly shows the browser's directory window and select the file from that and can directly uploads to the server.

View 2 Replies

Upload File On Click Of Image Button

Jun 17, 2010

I have an 'Attach image button' in my web page, I don't want see the the file upload control cannot use any third party tools in my page. On the click of the 'Attach image button' it will directly shows the browser's directory window and select the file from that and can directly uploads to the server.

View 1 Replies

Display Image From Memory Using File Upload?

Mar 29, 2010

So I'm working on a site that is going to need a file upload control where the user would be able to upload an image, and then the page would postback causing the image to appear for their viewing (before they submit the data to the database, the image is being stored as type image). What I do now is have my own private web form where people send me their image, I format it accordingly and use the following simple code to upload it:

byte[] newimage = fileUpImgFile.FileBytes;
var myDataTable = (from item in context.TypeSet where item.Number == txtBxNumber.Text.Trim() select item).ToList();
foreach (Type item in myDataTable)
{
item.Photo = newimage;
}
context.SaveChanges();

Which works, but in this case, it would only work if the record exists already in the database so the person would have to save the data, then go back in and upload the image (inconvenient and inefficient). Is there a way to upload it, store it in memory, and then display it, without saving it to the database?

View 1 Replies

Web Forms :: Upload File Or Image From One Server To Another?

Aug 26, 2010

uploading image from one server to another server. i am developing one website [URL] and from this website i want to upload images to another website say [URL] using asp:fileupload control... is it possible to upload file or image from localhost machine to different server using fileupload.saveas method..

View 2 Replies







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