Upload client image in server using jquery and rest in .net

Posted by Shanpricol under jQuery on 6/7/2011 | Points: 10 | Views : 5958 | Status : [Member] | Replies : 4
Hi,

How to upload a image from client in a web application using jquery and rest service in .NET.




Responses

Posted by: Susanthampy on: 6/7/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

check this,

http://debugmode.net/2011/05/01/uploading-file-to-server-from-asp-net-client-using-wcf-rest-service/

Regards,
Susan

Shanpricol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 6/7/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Good example Susan!!! Nicely explained!!!

Thanks
Karthik
www.f5Debug.net

Shanpricol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanpricol on: 6/8/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Thanks for the reply.You have written the code in codebehind of aspx.
Instead I should write in jquery.
My requirement is to write the code in jquery and send to REST because we use only html files and not aspx.


I am using html ,jquery and rest in .net.
If I use <asp:FileUpload ID="flup" runat="server" /> control I can get flup.FileContent and upload images.

But the requirement is I am using <input type="file" runat="server" id="fileup" />.
I want to send the filename and filecontent as parameter from jquery to the REST FileUpload method which is written in .net



protected void btnSubmit_Click(object sender, EventArgs e)

{

FileUpload(flup.FileName, flup.FileContent);

}

private void FileUpload(string fileName, Stream fileStream)

{

FileStream fileToupload = new FileStream("D:\\FileUpload\\" + fileName, FileMode.Create);

byte[] bytearray = new byte[10000];

int bytesRead, totalBytesRead = 0;

do
{

bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);

totalBytesRead += bytesRead;

} while (bytesRead > 0);

fileToupload.Write(bytearray, 0, bytearray.Length);

fileToupload.Close();

fileToupload.Dispose();

}


Shanpricol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 6/8/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Thanks Karthikanbarasan

Regards,
Susan

Shanpricol, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response